Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4. Your grade point average (GPA) is calculated by dividing the total amount of

ID: 3726266 • Letter: 4

Question

4. Your grade point average (GPA) is calculated by dividing the total amount of grade points earned by the total amount of credit hours attempted. Your grade point average may range from 0.0 to a 4.0. To get the example student's GPA, the total grade points are divided by the total credit hours attempted. Here is the simple formula to calculate the GPA ( Course GP * Course Credit/ Gradeable Credits ) Write a program to print the GPA of 5 Course Areas. (Please note there are different ways to write this program) For this question I would like to see 2 different programs for attaining your result. For instance you can use the scanner function in one of them, the other you can use command line arguments , or standard values.

Programming for Java

Explanation / Answer

/**The java program that prompts user to enter 4 credit
* and grades and calculates the gpa value and print on
* console*/
//StudentGPA.java
import java.util.Scanner;
public class StudentGPA
{
   public static void main (String args[])
   {
       String grade = "";
       double [] credits=new double[4];
       double gradeValue=0;
       double [] pts=new double[4];
       double totalPts= 0;
       double totalCredits=0;
       double gpa;
       //Create a Scanner object
       Scanner scanner = new Scanner (System.in);
      
       //Read four credits and grades
       for (int i = 0; i < credits.length; i++)
       {
           System.out.println("Please enter the number of credits of the class (A number)");
           credits[i] = Double.parseDouble(scanner.nextLine());
           System.out.println("Please enter your grades for the class ");
           System.out.println("Capital letters such as A,A-,B,B-,C+,C,D+,D,F,FX)");
           grade=scanner.nextLine();
          
           //check if grades is equals any of given grade letters
           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");
           pts[i] = gradeValue;
           //add to totalPts
           totalPts += credits[i] * pts[i];
           //add to totalCredits
           totalCredits+=credits[i];
       }
       //calculate gpa
       gpa= totalPts / totalCredits;
       //print gpa on console
       System.out.printf("Your GPA is: %.2f ", + gpa);
   }
}

Sample Output :
Please enter the number of credits of the class (A number)
4
Please enter your grades for the class
Capital letters such as A,A-,B,B-,C+,C,D+,D,F,FX)
A
Please enter the number of credits of the class (A number)
4
Please enter your grades for the class
Capital letters such as A,A-,B,B-,C+,C,D+,D,F,FX)
A
Please enter the number of credits of the class (A number)
4
Please enter your grades for the class
Capital letters such as A,A-,B,B-,C+,C,D+,D,F,FX)
A
Please enter the number of credits of the class (A number)
4
Please enter your grades for the class
Capital letters such as A,A-,B,B-,C+,C,D+,D,F,FX)
A
Your GPA is: 4.00

------------------------------------------------------------------------------------------
//Using Standard values
/**The java program that sets standard values for 4 credit
* and grades and calculates the gpa value and print on
* console*/
//StudentGPA.java
import java.util.Scanner;
public class StudentGPA
{
   public static void main (String args[])
   {
       String grade = "";
       //Create standard values for gpa calculation
       double [] credits=new double[]{4,4,4,4};      
       String[] gradeLetter=new String[]{"A","A","A","A"};
      
       double gradeValue=0;
       double [] pts=new double[4];
       double totalPts= 0;
       double totalCredits=0;
       double gpa;
       //Create a Scanner object
       Scanner scanner = new Scanner (System.in);
      
       //Read four credits and grades
       for (int i = 0; i < credits.length; i++)
       {
           grade=gradeLetter[i];
           //check if grades is equals any of given grade letters
           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");
           pts[i] = gradeValue;
           //add to totalPts
           totalPts += credits[i] * pts[i];
           //add to totalCredits
           totalCredits+=credits[i];
       }
       //calculate gpa
       gpa= totalPts / totalCredits;
       //print gpa on console
       System.out.printf("Your GPA is: %.2f ", + gpa);
   }
}


Sample Output :
Your GPA is: 4.00

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote