if (choice == 1) {
do {//do while block
try {//try catch block for exception handeling
// collect grades of tests
for (int i = 0; i < noTests; i++) {
System.out.printf("Enter grade number for %s %s %d: ", grad.getFirstname(), grad.getLastname(), i + 1);
grad.setGrades(scan.nextInt());
flag = false;
}
} catch (InputMismatchException IME) {//catch begin
System.err.printf("Exception!\nYou must enter a number. Please try again.\n", IME);//check for improper imput
scan.nextLine();
flag = true;//return to top if ture is false
}
} while (flag);//End do loop
do {//do while block
try {//try catch block for exception handeling
System.out.printf("Enter Midterm grade for: %s %s ", grad.getFirstname(), grad.getLastname());
grad.setmidtermgrad(scan.nextInt());
flag = false;
} catch (InputMismatchException IME) {//catch begin
System.err.printf("Exception!\nYou must enter a number. Please try again.\n", IME);//check for improper imput
scan.nextLine();
flag = true;//return to top if ture is false
}
} while (flag);//End do loop
do {
try {//try catch block for exception handeling
System.out.printf("Enter final grade for: %s %s ", grad.getFirstname(), grad.getLastname());
grad.setfinalgrade(scan.nextInt());
flag = false;
} catch (InputMismatchException IME) {//catch begin
System.err.printf("Exception!\nYou must enter a number. Please try again.\n", IME);//check for improper imput
scan.nextLine();
flag = true;//return to top if ture is false
}
} while (flag);//End do loopp
//collect information and display results
System.out.printf("Average grade for: %s %s %.2f\n", grad.getFirstname(), grad.getLastname(), grad.getGradeAvg());
System.out.printf("THE FINAL GRADE FOR STUDENT: %s %s %.2f\n", grad.getFirstname(), grad.getLastname(), grad.getFinalGrade());
} else if (choice == 2) {//begin else statement
do {//do while block
try {//try catch block for exception handeling
// collect grades of tests
for (int i = 0; i < noTests; i++) {
System.out.printf("Enter grade number %d: ", i + 1);
Grad.setGrades(scan.nextInt());
}
flag = false;
} catch (InputMismatchException IME) {//catch begin
System.err.printf("Exception!\nYou must enter a number. Please try again.\n", IME);//check for improper imput
scan.nextLine();
flag = true;//return to top if ture is false
}
} while (flag);//End do loop
do {
try {//try catch block for exception handeling
System.out.printf("Enter final grade for: %s %s ", Grad.getFirstname(), Grad.getLastname());
Grad.setfingrade(scan.nextInt());
flag = false;
} catch (InputMismatchException IME) {//catch begin
System.err.printf("Exception!\nYou must enter a number. Please try again.\n", IME);//check for improper imput
scan.nextLine();
flag = true;//return to top if ture is false
}
} while (flag);//End do loop
System.out.printf("Average grade for: %s %s %.2f\n", Grad.getFirstname(), Grad.getLastname(), Grad.getGradeAvg());
System.out.printf("THE FINAL GRADE FOR STUDENT: %s %s %.2f\n", Grad.getFirstname(), Grad.getLastname(), Grad.getFinGrade());
}
} //End Main Method
} //End Class Egingras_week13