Create a class named Student A Student has fields instance v

Create a class named Student.

A Student has fields (instance variables) for an ID number, number of credit hours earned, quality points, and GPA. Write a constructor with no parameters that sets the ID number to 9999, the credit hours to 3 and quality points to 10, then calls a method (calculateGPA) to set the GPA to quality points divided by credit hours. Write \"setter\" methods (e.g., setIdNumber) to assign values to all fields except GPA and \"getter\" methods (e.g., getIdNumber) to retrieve the value in each field. Write a (void) method to display the values of all fields of Student. Save this class as Student.java.

Write a class named ShowStudent that instantiates two Student objects from the class you created, then uses data input by the user (via a Scanner) and setter methods to change the values for one of the Students. Note that you\'ll need to call caculateGPA to recalculate GPA after changing other data. Call the getter methods to display the info for each student. Save the application as ShowStudent.java.

Sample output should look like:

Student ID: 18429

Credit Hours: 12.0

Quality Points: 38

GPA: 3.16666667

Solution

package ecommerceapp;

public class Student {

   private int IDNumber;
   private int creditHours;
   private int qualityPoints;
   private double GPA;
  
   public Student() {
       this.IDNumber=9999;
       this.creditHours=3;
       this.qualityPoints=10;
        calculateGPA();  
  
   }
  
  

   public int getIDNumber() {
       return IDNumber;
   }

   public void setIDNumber(int iDNumber) {
       IDNumber = iDNumber;
   }

   public int getCreditHours() {
       return creditHours;
   }

   public void setCreditHours(int creditHours) {
       this.creditHours = creditHours;
   }

   public int getQualityPoints() {
       return qualityPoints;
   }

   public void setQualityPoints(int qualityPoints) {
       this.qualityPoints = qualityPoints;
   }

   public double calculateGPA(){
  
   this.GPA=this.qualityPoints/this.creditHours;
   return this.GPA;
   }
  
   public void display(){
       System.out.println(\"\ \ \ Student details: \");
      
       System.out.println(\"Student ID: \"+IDNumber);
       System.out.println(\"Credit Numbers: \"+creditHours);
       System.out.println(\"Quality Points: \"+qualityPoints);
       System.out.printf(\"GPA: %.8f\",GPA);
              
   }

}


/*


Student details:
Student ID: 9999
Credit Numbers: 3
Quality Points: 10
GPA: 3.00000000


Student details:
Student ID: 18429
Credit Numbers: 12
Quality Points: 49
GPA: 4.00000000

*/


Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site