101k views
3 votes
Case 2: 1a. Create a class named Student. This class has attributes (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 an attribute for grade point average. Include a method that calculates the grade point average (equal to number of points earned divided by credit hours earned), and then displays the student number and grade point average in the following format: "The GPA for Student Number XXX is YYY". Note that XXX is the actual student number and YYY is the actual grade point average. Though credit hours earned and points earned will always be in whole (integer) numbers, make sure that you are able to calculate and display GPAs with decimal positions (e.g., 3.1).

User JuniKim
by
4.4k points

1 Answer

4 votes

Answer:

The java code will be:

// Student.java

// creates a class to store info about a student

class Student

{

// the private data members

private int IDnumber;

private int hours;

private int points;

private static int lastStudentID;

// the public get and set methods

public void setIDnumber()

{

lastStudentID += 1;

IDnumber = lastStudentID;

}

public int getIDnumber()

{

return IDnumber;

}

public void setHours(int number)

{

hours = number;

}

public int getHours()

{

return hours;

}

public void setPoints(int number)

{

points = number;

}

public int getPoints()

{

return points;

}

// methods to display the fields

public void showIDnumber()

{

System.out.println("ID Number is: " + IDnumber);

}

public void showHours()

{

System.out.println("Credit Hours: " + hours);

}

public void showPoints()

{

System.out.println("Points Earned: " + points);

}

public double getGradePoint()

{

return (double) (points / hours);

}

}

User Jellen Vermeir
by
4.9k points