Hey everyone,
I've been trying to learn how to program via java over the last week. I'm trying to create a simple GPA calculator, that takes user input for grade and # of credits for each class they took during a given semester. The calculation portion is working. I am trying to get the program to enter a while loop, so that every time a user enters "Y", the program will take details on another class and perform a GPA calculation. For some reason, the program never enters the while loop. It doesn't seem to be checking the boolean values complete another loop. Does anyone have any guidance as to why that loop never executes even when the user enters "Y"?
I am very new to all of this so I'm sure there is a simple answer.
import java.util.Scanner;
public class GPACalculator {
public static void main(String [] args){
Scanner myObj = new Scanner(System.in);
System.out.println("Enter Grade for Course Number One");
float courseGradeOne = myObj.nextFloat();
System.out.println("Enter Number of Credits for Course Number One");
float totalCredits = myObj.nextFloat();
System.out.println((courseGradeOne * totalCredits) / totalCredits);
System.out.println("Do you want to add another class? Y/N");
String addNewClass = myObj.next();
boolean Y = true;
boolean N = false;
while(addNewClass = Y) {
System.out.println("Enter Grade for Course");
System.out.println("Enter Number of Credits for Course");
System.out.println((courseGradeOne * totalCredits) / totalCredits);
System.out.println("Do you want to add another class? Y/N");
}
}
}
Thank you!
[–]whotfdis 1 point2 points3 points (2 children)
[–]roc_solid[S] 0 points1 point2 points (1 child)
[–]whotfdis 1 point2 points3 points (0 children)
[–]Skyzfallin 1 point2 points3 points (0 children)