This question already has an answer here:
- How do I compare strings in Java? 23 answers
This program takes user input, prints a trasnscipt, and calculates gpa for semester and total. It is all working correctly so far (there are three other classes not visible). Except my condition on the if statements towards the bottom never correctly initialize. This throws off the whole program because the methods inside of the if statements are used to add the grade into lists and those lists are used to calculate GPAs. There are identical if statements for each potential grade received.
public class MainController {
public static void main(String[] args) {
String aLetterGrade;
ConsoleView aView = new ConsoleView();
ConsoleViewSemester aPrintGPA = new ConsoleViewSemester();
ArrayList<Object> grades = new ArrayList<Object>();
SemesterGrades aSemesterGrade = new SemesterGrades();
Scanner school = new Scanner(System.in);
Scanner classId = new Scanner(System.in);
Scanner profName = new Scanner(System.in);
Scanner credits = new Scanner(System.in);
Scanner letterGrade = new Scanner(System.in);
Scanner newGrades = new Scanner(System.in);
Scanner end = new Scanner(System.in);
Scanner yesNo = new Scanner(System.in);
boolean initialize;
initialize = false;
System.out.print("Do you have grades to enter(enter 0 for no and 1 for yes): ");
int no = yesNo.nextInt();
if (no == 0) {
initialize = true;
}
while (initialize != true ) {
//SemesterGrades aSemesterGrade = new SemesterGrades();
GetTotals aTotals = new GetTotals();
System.out.print("Enter the two letter ID for the school the course is in: ");
String aSchool = school.next();
System.out.print("Enter the course ID: ");
int aClassId = classId.nextInt();
System.out.print("Enter the professor's name: ");
String aProfName = profName.next();
System.out.print("Enter the amount of credits taken: ");
int aCredits = credits.nextInt();
System.out.print("Enter the letter grade recieved if the course is completed, otherwise enter null: ");
aLetterGrade = letterGrade.next();
System.out.print("Is that all of your semesters grades(enter -1 to stop, any other number to continue)?: ");
int aEnd = end.nextInt();
if ((aLetterGrade == "a") || (aLetterGrade == "A") || (aLetterGrade == "a+") || (aLetterGrade == "A+")) {
double aGPRecieved = 4.0;
aSemesterGrade.getGPs(aGPRecieved);
aTotals.getGPs(aGPRecieved);
}
if ((aLetterGrade == "a-") || (aLetterGrade == "A-")) {
double aGPRecieved = 3.7;
//gradePoints.add(aGPRecieved);
aSemesterGrade.getGPs(aGPRecieved);
aTotals.getGPs(aGPRecieved);
}
Aucun commentaire:
Enregistrer un commentaire