I'm writing a simple method that takes grades as input from the user and calculates the Grade Point Average. Here is my code:
public static double calculateGPA(){
Scanner in = new Scanner(System.in);
double totalGradePoints = 0; // total grade points
int numClasses = 0; // total classes completed
boolean doneInput = false; // returns true when use is done inputting grades
System.out.println("Enter all your grades (A,B,C,D,F) and enter 'done' if you are done entering your grades.");
while (!doneInput) {
String grade = in.next();
if (grade == "A") {
totalGradePoints += 4;
numClasses++;
} else if (grade == "B") {
totalGradePoints += 3;
numClasses++;
} else if(grade == "C") {
totalGradePoints += 2;
numClasses++;
} else if(grade == "D") {
totalGradePoints += 1;
numClasses++;
} else if(grade == "F") {
numClasses++;
} else {
doneInput = true;
} //end if - else-if - else statement
}//end while loop
double unwtGPA = (totalGradePoints/numClasses);
return unwtGPA;
}
When I tested the method, I was only able to input one grade and none of the variables incremented, can somebody tell me what's wrong with the code?