-
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.
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));
}
}
}
-
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