Next, include methods to assign values to all fields separately. For example, one method should assign ID number, another should assign credit hours earned, etc. A Student also has a field for grade point average. Include a method to compute the grade point average field by divinding points by credit hours earned. Write methods to display the values in each Student field.
Write a class named ShowStudent that instantiates a Student object from the class you created above. Set the necessary values and compute the Student grade point average, and then display all the values associated with the Student. Create three different students with different values.
I write it and it executes but then has errors in it..I dont know what the issue is I am using NetBeans
Expand|Select|Wrap|Line Numbers
- package student;
- /**
- *
- * @author rlewis07
- */
- javac -cp . *.java
- ...
- java -cp . ShowStudent
- class Student
- {
- // the private data members
- private int IDnumber;
- private int hours;
- private int points;
- // constructor added in last part of project
- Student()
- {
- IDnumber = 77375;
- points = 12;
- hours = 3;
- }
- // end of constructor
- // the public get and set methods
- public void setIDnumber(int number)
- {
- IDnumber = 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;
- }
- }
Expand|Select|Wrap|Line Numbers
- package student;
- /**
- *
- * @author rlewis07
- */
- public class ShowStudent
- {
- public static void main (String args[])
- {
- Student pupil = new Student();// 2 cannot resolve sybmol... points to 'S' in Student
- pupil.showIDnumber();
- pupil.showPoints();
- pupil.showHours();
- System.out.println("The grade point average of the studnet created by constructor is "
- + pupil.getGradePoint()+"\n\n");
- Student s2 = new Student();// 2 cannot resolve sybmol points to 'S in Student
- s2.setIDnumber(12345);
- s2.setPoints(66);
- s2.setHours(20);
- s2.showIDnumber();
- s2.showPoints();
- s2.showHours();
- System.out.println("The grade point average of another student is "
- + s2.getGradePoint()+"\n");
- }
- }