In: Computer Science
PLEASE EXPLAIN ANSWER. USING JAVA via jGRASP
a. Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point average field by dividing points by credit hours earned. Write methods to display the values in each Student field. Save this class as Student.java.
b. Write a class named ShowStudent that instantiates a Student object from the class you created and assign values to its fields. Compute the Student grade point average, and then display all the values associated with the Student. Save the application as ShowStudent.java.
c. Create a constructor for the Student class you created. The constructor should initialize each Student’s ID number to 9999, his or her points earned to 12, and credit hours to 3 (resulting in a grade point average of 4.0). Write a program that demonstrates that the constructor works by instantiating an object and displaying the initial values. Save the application as ShowStudent2.java
A) Student.java
import.java.util.*;
Public class Student
{
int sid;
int credithours;
int point;
double averagegarde;
//constructor to assign intial values
public student()
{
this.sid = 9999;
this.credithours = 3;
this.points=12;
}
//method to assign values to all fields
public void setCredithours (int credithours)
{
this. credithours =credithours;
}
public void setPoints (int points)
{
this. points =points;
}
public void setSid (int sid)
{
this. sid=sid;
}
//method to compute the grade point average field by dividing points by credit hours earned
public void compute Averagegrade()
{
this.averagegrade = this.points/ this.credithourse;
}
// method to display the values in each student filed
public void showSid()
{
System.out.println("Student id is : " + this.sid);
}
public void showPoints()
{
System.out.println("Number of points earned : " + this.points);
}
public void showCredithours()
{
System.out.println("Number of credithours earned : " + this.credithours);
}
public void showAveragegrade()
{
System.out.println("Averagegrade point: " + this.averagegrade);
}
}
B)ShowStudent.java.
import.java.util.*;
public class ShowStudent
{
public static void main(String[ ] args)
{
//create student object
Student student1 = new Student();
//set student parameters
student1. setCredits(4);
student1.setID(1);
student1.setPoints(4);
//calculate GPA and assign to variable
double gradepoint = student1.calculateGPA( student1.getPoints(), student1.getCredits());
System.out.println("Student ID: " +student1.getID());
System.out.println("Number of credits: " +student1.getCredits());
System.out.println("Number of points: " +student1.getPoints());
System.out.println("GPA: " + gradepoint);
}
}
C)ShowStudent2.java.
// here's the student class
import.java.util.*;
public class Student
{
private int ID;
private int creditHours;
private int pointsEarned;
double GPA;
public Student()
{
}
public Student(int id, int hrs, int pts)
{
ID=id;
creditHours=hrs;
pointsEarned=pts;
}
public double getGPA()
{
return GPA;
}
public void setGPA()
{
GPA = (double)pointsEarned / creditHours;
}
public void setID(int number)
{
ID = number;
}
public int getID()
{
return ID;
}
public void setCreditHours(int hours)
{
creditHours = hours;
}
public int getcreditHours()
{
return creditHours;
}
public void setPointsEarned(int points)
{
pointsEarned points;
}
public int getPointsEarned()
{
return pointEarned;
}
}