Averaging Grades
I an new to JAVA and am stuck. I need to make a program that will allow input of grades. If an entered grade is less than 0 or more than 100 an error message needs to be displayed. The Loop function needs to end when a certain value is entered and then the other values need to be averaged. I have what I've come up with so far, but its still not working. I need to have this finished by tonight so if there is anyone out there that can send some help my way I would appreciate it.
Thanks!
import javax.swing.*;
publicclass Grades2
{
publicstaticvoid main(String[] args)
{
int count = 0;// Initialize these to zero.
int total = 0;// Initialize these to zero
int avg = 0;// Initialize these to zero.
int input;// Don't need to initialize, but it won't hurt
// Display a message requesting a grade between 0 and 100
System.out.println("Enter numerical grades");
input = value;// Store the input to variable input
while(input != 999){// If they entered 999, the while loop will not run.
if ((input >= 0) && (input <= 100))// Check if value is in the range of 0 to 100
{
count ++;// Increment the number of values input
total += input;// Add the input to the running total
}
else
{// the value was not between 0 and 100, the while loop will check to see if it is 999
JOptionPane.showMessageDialog(null,"Enter a valid grade",
"Grades Program", JOptionPane.INFORMATION_MESSAGE);
// Do not increment count
// Do not increment the total.
}
input = JOptionPane.showInputDialog("Enter a Final Grade: ");
// Input = new value;
}// This loop will continue to run until the user enters 999 as the input
if (count == 0){// I'm doing this check because you don't want to do a divide by zero
JOptionPane.showMessageDialog(null,"No grade has been issued",
"Grades Program", JOptionPane.INFORMATION_MESSAGE); ;
}
else{
System.out.println("The average is: " + total / count);
}
}
}

