[Please Help] Grading Program
This program is actually part of an assignment that does multiple things, but I'll remove the unnecessary parts. This program is designed to prompt the user for a grade. If the grade is A,B,C,D, or F, the program will ask for the next grade until the user enters Z. If the input is anything but a valid grade or Z, the program is supposed to display:
"< (User Input) is NOT an acceptable grade>"
and then prompt the user for the grade again.
The problem is right now, when the program is run, it is not prompting the user for a grade and instead displays "< is NOT an acceptable grade>" over and over, and the program loops endlessly.
Any suggestions?
Code:
Code:
import java.util.Scanner;
public class gradesloop{
public static void main (String [] args){
Scanner Reader = new Scanner(System.in);
String Grade;
Choice = 0;
TotalGrades = 0;PassGrades = 0; FailGrades = 0;PassRound = 0;
FailRound =0;StopLoop = 0;
Grade = "X";
System.out.print("Enter Grade #" + TotalGrades);
Grade = Reader.nextLine();
while (!("Z".equals(Grade))){
if ("A".equals(Grade)) {
TotalGrades ++;
PassGrades ++;
}
else if ("B".equals(Grade)) {
TotalGrades ++;
PassGrades ++;
}
else if ("C".equals(Grade)){
TotalGrades ++;
PassGrades ++;
}
else if ("D".equals(Grade)){
TotalGrades ++;
PassGrades ++;
}
else if ("F".equals(Grade)){
TotalGrades ++;
FailGrades ++;
}
else{
System.out.println ("< " + Grade + " is NOT an acceptable grade>");
}
}
System.out.print("Enter Grade # " + TotalGrades);
Grade = Reader.nextLine();
while (("Z".equals(Grade)) && StopLoop == 0){
if (TotalGrades == 0){
System.out.println("0 students total");
System.out.println("0 students passed");
StopLoop = 1;
}
else{
System.out.println(TotalGrades + " students total");
System.out.println(PassGrades + " students passed: ");
System.out.println(FailGrades + "stduents failed: ");
StopLoop = 1;
}
}
}