loading
Create GPA Calculator in Java Application program

The purpose of this instruction set is how to calculate your GPA during the semester. Calculating your GPA (Grade Point Average) is easy and essential. Knowing your GPA is important in evaluating your improvement and determining your academic standing for any given semester. The first thing that your future employer will look at in resume is your GPA because your grades can tell a lot about you as a person. Therefore it’s important to know how to calculate your GPA and see what you need to improve. Follow the steps below to calculate your GPA in Java.

Step 1: Install Java Developers Kit - download: JDK 6
(http://www.oracle.com/technetwork/java/javase/downloads/index.html)
And Install DrJava Introductory Programming Environment - download: DrJava Stable Release (http://www.drjava.org/)

Step 2: Before writing your codes you have to start your Java with “import java.util.Scanner;”. This tool allows users to input their data in. Then you need to create a class method as public class the name of your program, along with main method like public static void main (String args[ ]) and save it.
Note for each method you must use open and close bracket. The brackets tell the computer that the code belongs to the method.

Step 3: Declare and initialize your variables. In this step you need to know what type of data you should use. You should use string for grade to declare your variable because users need to enter grade in letter such as A, B+, C-, etc.  For declaring credit for each unit, total points for each class, total credits that you earn, and GPA you should use double because it might be decimals.
 
Step 4: Ask user to input data. Note the classes you want to include to figure out a specific GPA, e.g., a GPA for your minor or major.
• System.in stores users’ information (input).
For example:
- Scanner console = new Scanner (System.in);
• System.out.println is output and you can print your result.
For example:
- System.out.println("Please enter the number of credits of the class 1 (A number)");
- credit1 = console.nextDouble();


Step 5: Assign points to each grade for the included classes.
• Use if else statement to compare student grade with grade value and considering input validation.
• For each class, multiply the grade points by the number of units.
Note you need if/else statement and formula for all units, once you done with your first unit you can copy/paste the if/else statement and formula but DON’T FORGET TO CHANGE THE UNIT NAME.

Step 6: Create a formula to calculate your GPA.
• Add the total grade points you identified in Step above.
• Divide the total number of grade points by the total number of units (credit).
• The result is your GPA.

Step 7: print out the GPA and round it by two decimals.
• Use System.out.printf("Your GPA is: %.2f\n", + gpa);
• Printf allows user to format their output.

Step 8: close your statement and program by using close brackets “}”.

Step 9: Compile and run the program.
• Compiler translates the code into computer language which is binary (0s and 1s). Also marks your syntax errors.
• Run button execute and test the program.

Step 10: test and double check your result and make sure it’s correct. (Double check for logic error because sometimes your result logically is wrong).

This is code algorithm for GPA Calculator:
 “import java.util.Scanner;
public class StudentGPA {
public static void main (String args[]){

  String grade = "";
  double credit1;
  double credit2;
  double credit3;
  double credit4;
  double gradeValue=0;
  double totPtsClass1=0;
  double totPtsClass2=0;
  double totPtsClass3=0;
  double totPtsClass4=0;
  double totPts=0;
  double totalCredits= 0;
  double gpa;

  Scanner console = new Scanner (System.in);
  System.out.println("Please enter the number of credits of the class 1 (A number)");
  credit1 = console.nextDouble();
  System.out.println("Please enter your grades for the class 1(Capital letters such as A,B+, C-)");
  grade = console.next();
 
  if (grade.equals ("A"))
    gradeValue= 4.00;
  else if (grade.equals("A-"))
    gradeValue= 3.67;
  else if (grade.equals("B+"))
    gradeValue = 3.33;
  else if (grade.equals("B"))
    gradeValue = 3.00;
  else if (grade.equals ("B-"))
    gradeValue = 2.67;
  else if (grade.equals("C+"))
    gradeValue = 2.33;
  else if (grade.equals("C"))
    gradeValue = 2.00;
  else if (grade.equals ("D+"))
  gradeValue = 1.33;
  else if (grade.equals ("D"))
    gradeValue = 1.00;
  else if (grade.equals ("F"))
    gradeValue = 0;
  else if (grade.equals ("FX"))
    gradeValue = 0;
  else
    System.out.println ("Invalid Grade");
 
  totPtsClass1 = gradeValue * credit1;
 
  System.out.println("Please enter the number of credits of the class 2 (A number)");
  credit2 = console.nextDouble();
  System.out.println("Please enter your grades for the class 2 (Capital letters such as A,B+, C-)");
  grade = console.next();
 
  if (grade.equals ("A"))
    gradeValue= 4.00;
  else if (grade.equals("A-"))
    gradeValue= 3.67;
  else if (grade.equals("B+"))
    gradeValue = 3.33;
  else if (grade.equals("B"))
    gradeValue = 3.00;
  else if (grade.equals ("B-"))
    gradeValue = 2.67;
  else if (grade.equals("C+"))
    gradeValue = 2.33;
  else if (grade.equals("C"))
    gradeValue = 2.00;
  else if (grade.equals ("D+"))
  gradeValue = 1.33;
  else if (grade.equals ("D"))
    gradeValue = 1.00;
  else if (grade.equals ("F"))
    gradeValue = 0;
  else if (grade.equals ("FX"))
    gradeValue = 0;
  else
  System.out.println ("Invalid Grade");

  totPtsClass2 = gradeValue * credit2;
 
  System.out.println("Please enter the number of credits of the class 3 (A number)");
  credit3 = console.nextDouble();
  System.out.println("Please enter your grades for the class 3 (Capital letters such as A,B+, C-)");
  grade = console.next();
 
  if (grade.equals ("A"))
    gradeValue= 4.00;
  else if (grade.equals("A-"))
    gradeValue= 3.67;
  else if (grade.equals("B+"))
    gradeValue = 3.33;
  else if (grade.equals("B"))
    gradeValue = 3.00;
  else if (grade.equals ("B-"))
    gradeValue = 2.67;
  else if (grade.equals("C+"))
    gradeValue = 2.33;
  else if (grade.equals("C"))
    gradeValue = 2.00;
  else if (grade.equals ("D+"))
  gradeValue = 1.33;
  else if (grade.equals ("D"))
    gradeValue = 1.00;
  else if (grade.equals ("F"))
    gradeValue = 0;
  else if (grade.equals ("FX"))
    gradeValue = 0;
  else
    System.out.println ("Invalid Grade");
 
    totPtsClass3 = gradeValue * credit3;
 
  System.out.println("Please enter the number of credits of the class 4 (A number)");
  credit4 = console.nextDouble();
  System.out.println("Please enter your grades for the class 4 (Capital letters such as A,B+, C-)");
  grade = console.next();
 
  if (grade.equals ("A"))
    gradeValue= 4.00;
  else if (grade.equals("A-"))
    gradeValue= 3.67;
  else if (grade.equals("B+"))
    gradeValue = 3.33;
  else if (grade.equals("B"))
    gradeValue = 3.00;
  else if (grade.equals ("B-"))
    gradeValue = 2.67;
  else if (grade.equals("C+"))
    gradeValue = 2.33;
  else if (grade.equals("C"))
    gradeValue = 2.00;
  else if (grade.equals ("D+"))
  gradeValue = 1.33;
  else if (grade.equals ("D"))
    gradeValue = 1.00;
  else if (grade.equals ("F"))
    gradeValue = 0;
  else if (grade.equals ("FX"))
    gradeValue = 0;
  else
    System.out.println ("Invalid Grade");
  totPtsClass4 = gradeValue * credit4;
 
  totPts= totPtsClass1+totPtsClass2+totPtsClass3+totPtsClass4;
  totalCredits = credit1+credit2+credit3+credit4;
  gpa= totPts / totalCredits;
 
  System.out.printf("Your GPA is: %.2f\n", + gpa);
}
}”
<p>Hello. I am trying to create a different type of calculator but I can't figure out how to code it into C+ . do you know how to create multiple inputs with variable bases into c+?</p>
<p>Hello ,</p><p>The above code is nice one. However, we shared in 5 different formats which will helpful for the beginners. Source of code : https://javatutoring.com/java-program-to-calculate-cgpa/</p>

About This Instructable

37,309views

8favorites

License:

More by vahiiiiiiid:Create GPA Calculator in Java Application program 
Add instructable to: