I don't know what am I doing wrong,
When I input number of courses it won't loop again just once?
What is wrong with the code?
Thanks
// EX 3
import java.util.*; // program uses class Scanner
public class ComputeGpa {
public static void main(String args[]) {
// create Gpa object myGpa and
// pass grade to constructor
Gpa myGpa = new Gpa("EX 3");
myGpa.displayMessage(); // display welcome message
Scanner in = new Scanner(System.in); //scanner input
double GPA = 0;
char gradeCh = 'k';
int credits = -1;
boolean isGradeCorrect = false;
boolean isCreditsCorrect = false;
System.out.println("\n");
System.out.print("Enter Number of courses: ");
int coursNumber = in.nextInt();
do // check number of courses
if (coursNumber <= 0)
{
System.out.println("Invalid number of courses - must be grater then 0");
System.out.println("\n");
System.out.print("Enter Number of courses: ");
coursNumber = in.nextInt();
}while (coursNumber <= 0);
System.out.println("\n");
for (int am = 1; am <= coursNumber; am++) {
while(!isGradeCorrect) // check grade
{
System.out.print("Enter grade (one character) : ");
String sGrade = in.next();
gradeCh = sGrade.charAt(0);
// validating input
switch (gradeCh) {
case 'a':
case 'A': {
isGradeCorrect = true;
break;
}
case 'b':
case 'B': {
isGradeCorrect = true;
break;
}
case 'c':
case 'C': {
isGradeCorrect = true;
break;
}
case 'd':
case 'D': {
isGradeCorrect = true;
break;
}
case 'f':
case 'F': {
isGradeCorrect = true;
break;
}
default:
System.out.print("Invalid grade - must enter exactly one lette");
System.out.println("\n");
}
}
System.out.println();
while(!isCreditsCorrect) // check credits
{
System.out.println("Enter Credits : ");
credits = in.nextInt();
System.out.println("\n");
if(credits >= 0 && credits <= 9)
{
isCreditsCorrect = true;
}
else
{
System.out.println("Invalid credits = must be between 0 and 9, inclusively");
System.out.println("\n");
}
}
myGpa.addTotals(gradeCh, credits);
System.out.println("\n");
GPA = myGpa.calcGpa();
System.out.printf("GPA: %.2f", GPA);
}
} // end main
} // end