Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

skip to main content menu Message alerts Subscription alerts Update alerts Side

ID: 3705374 • Letter: S

Question

skip to main content

menu

Message alerts

Subscription alerts

Update alerts

Side PanelExpand side panel

Breadcrumb:

Week 3 Project 

 

Previous Next 

Instructions

Add additional information to the student class below such as name, address, major, and contact information along with all the getters and setters (methods) needed to access all data. Submit your code along with a sample run of your program. Comment all your code. Cite any sources of information you use. Write a note on the process of completing the assignment in a Microsoft Word document.

// ShowStudent.java// client to test the Student classclass ShowStudent{public static void main (String args[]){Student pupil = new Student(); // We need a new student named pupilpupil.setIDnumber(234); // We are setting pupil's ID number to 234pupil.setPoints(47); // We are setting pupil's points to 47pupil.setHours(15); // We are setting pupil's hours to 15pupil.showIDnumber(); // We are showing pupil's ID numberpupil.showPoints(); // We are showing pupil's pointspupil.showHours(); // We are showing pupil's hourseSystem.out.println("The grade point average is " +pupil.getGradePoint()); // we are calculating pupil's GPA}}class Student // this is the student class{// the private data membersprivate int idNumber;private int hours;private int points;// Constructor creates a new studentStudent(){idNumber = 9999; // a max IDpoints = 12; // starting out assuming 12 pointshours = 3; // starting out assuming 3 hours}// end of constructor// the public get and set methods fro pulil specific informationpublic void setIDnumber(int number) // pass in a number{idNumber = number; // assign the number}public int getIDnumber() // return a student ID{return idNumber;}public void setHours(int number) // pass in a number{hours = number; // assign the number to hours}public int getHours() // return the student's hours{return hours;}public void setPoints(int number) // pass in a number{points = number; // assign number to points}public int getPoints() // return the points{return points;}// methods to display the fieldspublic 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() // calculate the GPA with internal data{return (points * 1.0 / hours);// simple integer division will truncate the decimal places}}

Submission Details:

Create the code and sample run files.Write the process of completing the assignment in a Microsoft Word document.Zip the files as SU_ITS2105_W3_A2_LastName_FirstInitial.zip.

Explanation / Answer

ShowStudent.java

public class ShowStudent{

public static void main (String args[]){

Student pupil = new Student(); // We need a new student named

pupil.setIdNumber(234); // We are setting pupil's ID number to 234

pupil.setPoints(47); // We are setting pupil's points to 47

pupil.setHours(15); // We are setting pupil's hours to 15

pupil.showIDnumber(); // We are showing pupil's ID number

pupil.showPoints(); // We are showing pupil's points

pupil.showHours(); // We are showing pupil's hourse

System.out.println("The grade point average is " +pupil.getGradePoint()); // we are calculating pupil's GPA}}

}

}

Student.java

public class Student {

private int idNumber;

private int hours;

private int points;

public Student(){

}

public Student(int id, int h, int p) {

idNumber=id;

hours=h;

points=p;

}

public int getIdNumber() {

return idNumber;

}

public void setIdNumber(int idNumber) {

this.idNumber = idNumber;

}

public int getHours() {

return hours;

}

public void setHours(int hours) {

this.hours = hours;

}

public int getPoints() {

return points;

}

public void setPoints(int points) {

this.points = points;

}

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() // calculate the GPA with internal data

{return (points * 1.0 / hours);

}

}

Output:

ID Number is: 234
Points Earned: 47
Credit Hours: 15
The grade point average is 3.1333333333333333