Hey guys, I'm making a gpa calculator and almost have it completed but can't get it to read the grades and calculate the gpa properly. Any help would be great!
import java.util.Scanner;
public class StudentGPA {
public static void main (String args[]){
//User inputs the number of classes he/she has
Scanner input = new Scanner (System.in);
System.out.println("Please enter the amount of grades you have");
int classes;
classes = input.nextInt();
String Grade = "";
int totalCredits = 0;
int totalCreditsEarned = 0;
int credits;
double gpa;
double number=0;
//String of if and else statements that set the number to the appropriate GPA
if(Grade.equals("A")){
number = 4.0;
} else if(Grade.equals("A-")){
number = 3.67;
} else if(Grade.equals("B+")){
number = 3.33;
} else if(Grade.equals("B")){
number = 3.0;
} else if(Grade.equals("B-")){
number = 2.67;
} else if(Grade.equals("C+")){
number = 2.33;
} else if(Grade.equals("C")){
number = 2.0;
} else if(Grade.equals("C-")){
number = 1.67;
} else if(Grade.equals("D+")){
number = 1.33;
} else if(Grade.equals("D")){
number = 1.0;
} else if(Grade.equals("D-")){
number = 0.67;
} else if(Grade.equals("F")){
number = 0;
} else {
number = 0;
//Loop that ends once the student has put information in on all his classes
for(int count = 0; count < classes; count++)
{
//Reads the number of credits each class was
Scanner input2 = new Scanner (System.in);
System.out.println("Please enter the number of credits this class was (A number)");
credits = input2.nextInt();
//reads the letter grade using the String Grade prompt
Scanner input3 = new Scanner(System.in);
System.out.println("Please enter your grade for this class (Capital letters such as A, B+, C-)");
Grade = input3.next();
//algorithm for finding the GPA
totalCredits += credits;
totalCreditsEarned += (credits * number);
}
//for loop ends
//GPA is calculated for all the students classes
gpa = totalCreditsEarned / totalCredits;
//GPA is printed to the screen
System.out.println(gpa);
}
}
}