// gpa.java // basic kind of accurate gpa calculator with rudimentary introduction/welcome import java.util.Scanner; // program uses scanner import java.math.*; // math stuff public class gpa { //static double A; forget about this at the moment i dont know how to really use it yet //static double A_minus; //static double B_plus; //static double B; //static double B_minus; //static double C_plus; //static double C; //static double C_minus; //static double D; //static double F; // main method begins program execution public static void main( String[] args ) { // create Scanner to obtain input from command window Scanner input = new Scanner ( System.in ); // create a GradeBook object and assign it to myGradeBook gpacn myGradeBook = new gpacn(); // display initial value of courseName System.out.printf ( "Initial course name is: %s\n\n", myGradeBook.getCourseName () ); // prompt for and input course name System.out.println ( "Enter semester number (1,2,3,4,5, etc) :" ); String theName = input.nextLine(); // read a line of text myGradeBook.setCourseName ( theName ); // set the course name System.out.println(); // outputs a blank line // display welcome message after specifying course name myGradeBook.displayMessage(); // end main float c_num; // total number of courses calculated float c1g; // course1 grade float c2g; // course2 grade float c3g; // course3 grade float c4g; // course4 grade float c5g; // course5 grade float cum_prog; // program gpa 10scale float cum_gpa; // total semester gpa 4 scale float necvar; // equals 4 necvar = 4; System.out.print ("Enter the total number of courses for the semester: "); // prompt for input c_num = input.nextInt(); if (c_num == 3) { System.out.print ("Enter the number value that corresponds to the letter grade received for course one\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c1g = input.nextInt(); System.out.print ("Enter the number value that corresponds to the letter grade received for course two\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c2g = input.nextInt(); System.out.print ("Enter the number value that corresponds to the letter grade received for course three\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c3g = input.nextInt(); cum_prog = ((c1g + c2g +c3g) / ( c_num )); // calculate semester GPA for 3 courses cum_gpa = ( necvar - (cum_prog / necvar) ); System.out.println ("Your GPA for this semester is " + cum_gpa); } else if (c_num == 4) { System.out.print ("Enter the number value that corresponds to the letter grade received for course one\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c1g = input.nextInt(); System.out.print ("Enter the number value that corresponds to the letter grade received for course two\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c2g = input.nextInt(); System.out.print ("Enter the number value that corresponds to the letter grade received for course three\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c3g = input.nextInt(); System.out.print ("Enter the number value that corresponds to the letter grade received for course three\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c4g = input.nextInt(); cum_prog = ((c1g + c2g + c3g + c4g) / ( c_num)); // calculate semester gpa for 4 courses cum_gpa = ( necvar - (cum_prog / necvar) ); System.out.println ("Your GPA for this semester is " + cum_gpa); } else if (c_num == 5) { System.out.print ("Enter the number value that corresponds to the letter grade received for course one\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c1g = input.nextInt(); System.out.print ("Enter the number value that corresponds to the letter grade received for course two\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c2g = input.nextInt(); System.out.print ("Enter the number value that corresponds to the letter grade received for course three\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c3g = input.nextInt(); System.out.print ("Enter the number value that corresponds to the letter grade received for course three\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c4g = input.nextInt(); System.out.print ("Enter the number value that corresponds to the letter grade received for course three\n (1=A, 2=A-, 3=B+, 4=B, 5=B-,6=C+, 7=C, 8=C-, 9=D, 10=F: "); // prompt for input c5g = input.nextInt(); cum_prog = ((c1g + c2g + c3g + c4g + c5g) / ( c_num)); // calculate semester gpa for 5 courses cum_gpa = ( necvar - (cum_prog / necvar) ); System.out.println ("Your GPA for this semester is " + cum_gpa); } // end main }// end class gpa.java }

Alright here's the deal, I'm an amateur who's been building off of some of the sample things I've been shown and I tried to come up with a GPA calculator.

I'm familiar with using scanner to fill in variables with various integers or whatever, initially I was trying to have users enter in "A+" or even "A_plus" and have it represent 4.0 and 3.7 respectively etc.

Since I only know how to have it read integers the only way to make it semi-coherent was the really ugly system of type 1 for A+, 2 for A, 3 for A-, etc. Obviously the equation is easy if I were to have them enter 3.7, 4.0, 3.4, and stuff but that would defeat the entire purpose of the calculator since they are doing it to find out their grade in GPA by entering in their letter grades.

What I'm left with is a prettyugly equation (if you're wondering what the hell "necvar is for...)that leaves most calculations within 5% error (as small as <1% and large as 10%+.) But alas, I have no idea how to have them enter letter grades and have the code read them as their respective valuations. At one point I thought I was doing it with the static double stuff that I now have in // comment tags but I have since ditched that effort.

I've only been doing this stuff for a week and a half now and this is my first programming language at all besides some really basic HTML so bear with me please