Could you implement a gpa calculator so that it asks for a letter grade for each...

60.1K

Verified Solution

Question

Programming

Could you implement a gpa calculator so that it asks for aletter grade for each of four classes, calculates the gpa, andprints the GPA out along with the student id, major, and name.

/*****************************Student.java*************************/


public class Student {

   // private data members
   private String id;
   private String name;
   private String major;
   private double gpa;

   // default constructor which set the data member todefualt value
   public Student() {

       this.id = \"\";
       this.name = \"\";
       this.major = \"\";
       this.gpa = 0;
   }

   // parameterized constructor
   public Student(String id, String name, String major,double gpa) {
       this.id = id;
       this.name = name;
       this.major = major;
       this.gpa = gpa;
   }

   // getter and setter
   public String getId() {
       return id;
   }

   public void setId(String id) {
       this.id = id;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public String getMajor() {
       return major;
   }

   public void setMajor(String major) {
       this.major = major;
   }

   public double getGpa() {
       return gpa;
   }

   public void setGpa(double gpa) {
       this.gpa = gpa;
   }

   // print student data
   public void printStudent() {

       System.out.println(\"Student ID:\" + id);
       System.out.println(\"Student name: \"+ name);
       System.out.println(\"Student major:\" + major);
       System.out.println(\"Student GPA: \"+ gpa);
   }

}

/**************************StudentApplication.java*******************/


public class StudentApplication {

   public static void main(String[] args) {
      
       //create object by defaultconstructor
       Student s1 = new Student();
       //create object by overloadedconstructor
       Student s2 = new Student(\"S12345\",\"Virat Kohli\", \"Computer Science\", 4.5);
       //set the information of object1
       s1.setName(\"John Doe\");
       s1.setId(\"S123456\");
       s1.setMajor(\"Electronics\");
       s1.setGpa(4.0);
      
       s1.printStudent();
       System.out.println();
       s2.printStudent();
   }
}

Answer & Explanation Solved by verified expert
3.9 Ratings (505 Votes)
The java test program that create an instance of Student class and calls the method readClassGrades that prompts user to enter 4 credit hours and grade value and then print the student details with the gpa value StudentApplicationjava public class StudentApplication public static void mainString args create object by overloaded constructor Student s1 new StudentS12345 Virat Kohli Computer Science Call readClassGrades that prompts user to enter the grade and credit hours from user s1readClassGrades s1printStudent Studentjava import javautilScanner public class Student private data members private String id private String name    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students