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

Create a Java class or classes that averages a student\'s class grades to get th

ID: 3676680 • Letter: C

Question

Create a Java class or classes that averages a student's class grades to get their average GPA. The code has to follow the following criteria:

Write code for a Java program as follows: Create a class of your own with a main method that calls the constructor(s) and methods of your class can be reference variables (another class*) something interesting with your class's data. Perhaps use a conditional loop in your code in this method Create a minimum of three private data attributes for your class. These can all be primitive variables (int, char, long, double etc..), or they * Besides getter and setter methods, and at least one constructor in addition to the default, create at least one method that does

Explanation / Answer

GPA.java

import java.util.ArrayList;
import java.util.Scanner;
public class GPA{
   public static ArrayList ar = new ArrayList();
   public static int A = 4, B = 3, C = 2, F = 0;
   GPA(){
       set_grades();
   }
   public static ArrayList get_grades_of_student(){
       String s1,s2,s3;
       Scanner sc = new Scanner(System.in);
       //For example take 3 subjects and the grades are like A, B, C and F
       System.out.println("Enter Subject Grades : ");
       System.out.println("Subject 1");
       s1 = sc.next();
       ar.add(s1);
       System.out.println("Subject 2");
       s2 = sc.next();
       ar.add(s2);
       System.out.println("Subject 3");
       s3 = sc.next();
       ar.add(s3);
       return ar;
   }
   public void set_grades(){
       A = 4; B = 3; C = 2; F = 0;
   }
   public static double calculate_GPA(ArrayList ar){
       double gpa = 0;
       String ele = null;
       for(int i=0;i<ar.size();i++){
           ele = (String)ar.get(i);
           // Taking Grades points 4 for A, 3 for B, 2 for C and 0 for F
           if(ele.equals("A")){
               gpa = gpa + A;
           }else if(ele.equals("B")){
               gpa = gpa + B;
           }else if(ele.equals("C")){
               gpa = gpa + C;
           }else if(ele.equals("F")){
               gpa = gpa + F;
           }
       }
       gpa = gpa / 3;
       return gpa;
   }
   public static void main(String args[]){
       GPA gp = new GPA();
       ar = get_grades_of_student();
       double gpa = calculate_GPA(ar);
       System.out.println("Your Grade is : "+gpa);
   }
}