Write a program to calculate a students GPA.
What I cant figure is how to calculate ( Total= credit * grade + credit * grade...etc)
or
(GPA = Total/grade +grade etc...)
If you run this program, you will see my calculation off by a lot.
Please help.
import java.util.Scanner;
import java.io.*;
public class GPA
{
private int total;
private int credits;
private int grades;
private double gpa;
private int gradeCounter1;
private int creditCounter2;
public static void main(String[] args)throws IOException
{
Scanner key = new Scanner(System.in);
System.out.println("How many classes will you enter?");
int amount = key.nextInt();
key.nextLine();
int number;
int total = 0;
int credits = 0;
double gpa = 0;
int gradeCounter1 = 0;
int creditCounter2 = 0;
String className;
for
(number = 1;number <=amount;number++)
{
System.out.println("Enter Class Name and Course Number:");
className = key.nextLine();
System.out.println("Enter Grade:" );
String grade;
grade = key.nextLine();
char letter = grade.charAt(0);
gradeCounter1++;
System.out.println("How many Credits is this class?");
credits = key.nextInt();
creditCounter2++;
key.nextLine();
System.out.println("Class\tGrade \tCredits");
System.out.println(className + "\t"+ letter + "\t" + credits);
total += creditCounter2*gradeCounter1 ;
gpa = total/(number*letter);
if((letter =='Z') || (letter == 'z'))
{
System.out.println("Try Again");
}
else if((letter == 'A') || (letter == 'a'))
{
gpa = (gpa + 4.0) / number;
}
else if((letter == 'B') || (letter == 'b'))
{
gpa = (gpa + 3.0) / number;
}
else if((letter == 'C') || (letter == 'c'))
{
gpa = (gpa + 2.0) / number;
}
else if((letter == 'D') || (letter == 'd'))
{
gpa = (gpa + 1.0) / number;
}
else if((letter == 'F') || (letter == 'f'))
{
gpa = (gpa + 0.0) / number;
}
}
System.out.println("Total grade points: " + total);
System.out.println("Your GPA is a: " +gpa);
}
}