该程序接受用户输入,打印出总经,并计算学期和总学分的gpa。到目前为止,它们都正常工作(还有其他三个不可见的类)。除非我对if语句的底部条件始终无法正确初始化。因为if语句内部的方法用于将成绩添加到列表中,而这些列表用于计算GPA,所以这将引发整个程序。每个收到的潜在成绩都有相同的if陈述。
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);
}