How can I build my for loop in this GPA Calculator? Brand new to Java, and for our class we are required to ask for user's grade and credit hours 4 times, then calculate their average. We were instructed to use switch statements and loops, but not much other instruction. We just learned about for, while, and do loops. Here is what I have so far, not sure what to do next.
This is what output is supposed to look like.
public static void main(String[] args) {
String grade = "";
int creditHour = 0;
int pointsPerCourse = 0;
double gpa = 0.0;
Scanner scnr = new Scanner(System.in);
System.out.println("\t\t\tpointsPerCourse Calculator");
System.out.println("This program will calculate pointsPerCourses based on course grades");
for ();
{
System.out.print("Enter grade: ");
grade = scnr.nextLine();
System.out.print("Enter number of credits for grade: ");
creditHour = Integer.parseInt(scnr.nextLine());
}
switch (grade) {
case "A":
pointsPerCourse = 4 * creditHour;
case "B":
pointsPerCourse = 3 * creditHour;
case "C":
pointsPerCourse = 2 * creditHour;
case "D":
pointsPerCourse = 1 * creditHour;
default:
pointsPerCourse = 0 * creditHour;
}
gpa = (double) pointsPerCourse / creditHour;
System.out.printf("The GPA is %.1f ", gpa);
scnr.close();
}