Results 1 to 2 of 2
  1. #1
    Urgle is offline Member
    Join Date
    Oct 2008
    Posts
    30
    Rep Power
    0

    Default Convert to Applet

    How would I convert my program into a working applet? I just cant figure it out?
    It takes 10 grades input by a user then finds the average, number above average, and the number below average.

    Java Code:
    package AverageTestScore;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    
    public class AverageTestScore extends Applet
    {
            static BufferedReader stdin = new BufferedReader
        (new InputStreamReader (System.in));
        static InputStreamReader converter = new InputStreamReader (System.in);
    
            public static void main(String[] args) throws Throwable, IOException{
    
                    double[ ] grade = new double[10]; // assume no more than 70 grades
            int gradeCount = 0;
            double sum = 0;
    
            page.drawstring("Enter Grade: ");
    
                    double value = Double.parseDouble(stdin.readLine());
    
                    while(gradeCount < 10 && (value >= 0 && value <= 100)){
               grade[gradeCount] = value;
                   sum += grade[gradeCount];
               gradeCount++;
               System.out.print("Enter the next grade (Negative to skip to averages): ");
               value = Double.parseDouble(stdin.readLine());
       }
    
    
       if(gradeCount == 0)
           System.out.println("No valid grades were entered");
       else{
          double average = sum / gradeCount;
          int count = 0;
    
          for(int k = 0; k < gradeCount; k++)
               if(grade[k] > average)
                     count++;
    
          System.out.println("The average is: " + average);
          System.out.println("The number of grades above average is: " + count);
          System.out.println("The number of grades below the average is: " + (9-count));
      }
         }
         }

  2. #2
    monur is offline Member
    Join Date
    Nov 2008
    Posts
    4
    Rep Power
    0

    Default

    Hi,
    First of all you have to do your initialization process in applet's init() function, not main().
    I recommend you to search for some resources and learn applet life-cycle basics.

    HTH

Similar Threads

  1. convert XML using XSL
    By rajjan4u in forum XML
    Replies: 3
    Last Post: 11-20-2009, 04:37 PM
  2. Convert .java to .exe
    By susan in forum New To Java
    Replies: 6
    Last Post: 02-11-2009, 06:47 AM
  3. Convert the application from 9i to 10g
    By rahul999 in forum JDBC
    Replies: 5
    Last Post: 09-03-2008, 03:55 PM
  4. Convert a program to Applet
    By carl in forum Java Applets
    Replies: 2
    Last Post: 08-09-2007, 09:33 PM
  5. Replies: 4
    Last Post: 06-08-2007, 06:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •