Question
Java and the questions are the ones in the first picture public class Student { private String sID; private double gpa; private String program; public
Java and the questions are the ones in the first picture
public class Student {
private String sID; private double gpa; private String program;
public Student(String sID, double gpa, String program) { this.sID = sID; this.gpa = gpa; this.program = program; } /* * Purpose: set's this Student's sID to sID parameter value * Parameters: String - sID * Returns: nothing */ public void setSID(String sID) { this.sID = sID; }
/* * Purpose: returns this Student's sID * Parameters: none * Returns: String - the sID */ public String getSID() { return this.sID; } /* * Purpose: set's this Student's gpa * Parameters: double - gpa * Returns: nothing */ public void setGPA(double gpa) { this.gpa = gpa; }
/* * Purpose: returns this Student's grade * Parameters: none * Returns: double - the gpa */ public double getGPA() { return this.gpa; } /* * Purpose: set's this Student's program * Parameters: String - program * Returns: nothing */ public void setProgram(String program) { this.program = program; }
/* * Purpose: returns this Student's program * Parameters: none * Returns: String - the program */ public String getProgram() { return this.program; }
/* * Purpose: returns a String representation of this Student * in the form "sID:grade" * Parameters: none * Returns: String - the representation * */ public String toString() { return sID + ":" + gpa + ":" + program; }
/* * Purpose: returns true if this Student's sID * equals the other Student's sID * Parameters: none * Returns: boolean - true if equal, false otherwise */ public boolean equals(Student other) { return (this.sID.equals(other.sID)); } }
Tester Codes
public static void testInProgram() { System.out.println(" Starting inProgram tests"); /* List contents: list0: empty list1: v00123:6.7:Geography list2: v00123:6.7:Geography, v00246:9.0:Geography, v00357:8.2:Mathematics list3: v00123:6.7:Geography, v00555:7.8:Physics, v00987:4.5:Psychology, v00246:9.0:Geography v00357:8.2:Mathematics, v00149:7.2:Physics, v00001:8.4:Geography */ boolean result = false; result = list0.inProgram("Geography"); displayResults(!result, "inProgram on empty list searching for Geography"); result = list1.inProgram("Geography"); displayResults(result, "inProgram on list1 searching for Geography"); result = list1.inProgram("Mathematics"); displayResults(!result, "inProgram on list1 searching for Mathematics"); result = list3.inProgram("Geography"); displayResults(result, "inProgram on list3 searching for Geography"); result = list3.inProgram("Mathematics"); displayResults(result, "inProgram on list3 searching for Mathematics"); result = list3.inProgram("Biology"); displayResults(!result, "inProgram on list3 searching for Biology"); result = list3.inProgram("Physics"); displayResults(result, "inProgram on list3 searching for Physics"); } public static void testGetStudent() { System.out.println(" Starting getStudent tests"); /* List contents: list0: empty list1: v00123:6.7:Geography list2: v00123:6.7:Geography, v00246:9.0:Geography, v00357:8.2:Mathematics list3: v00123:6.7:Geography, v00555:7.8:Physics, v00987:4.5:Psychology, v00246:9.0:Geography v00357:8.2:Mathematics, v00149:7.2:Physics, v00001:8.4:Geography */ Student toFind1 = new Student("v00123", 6.7, "Geography"); Student toFind2 = new Student("v00321", 7.2, "Chemistry"); Student toFind3 = new Student("v00001", 8.4, "Geography"); Student result = null; result = list0.getStudent("v00123"); displayResults(result==null, "searching for student v00123 in empty list"); result = list1.getStudent("v00123"); displayResults(result.equals(toFind1), "searching for student v00123 in list1"); result = list1.getStudent("v00001"); displayResults(result==null, "searching for student v00001 in list1"); result = list3.getStudent("v00123"); displayResults(result.equals(toFind1), "searching for student v00123 in list3"); result = list3.getStudent("v00321"); displayResults(result==null, "searching for student v00321 in list3"); result = list3.getStudent("v00001"); displayResults(result.equals(toFind3), "searching for student v00001 in list3"); } public static void testAverageGPA() { System.out.println(" Starting averageGPA tests"); /* List contents: list0: empty list1: v00123:6.7:Geography list2: v00123:6.7:Geography, v00246:9.0:Geography, v00357:8.2:Mathematics list3: v00123:6.7:Geography, v00555:7.8:Physics, v00987:4.5:Psychology, v00246:9.0:Geography v00357:8.2:Mathematics, v00149:7.2:Physics, v00001:8.4:Geography */ double result = 0.0; double expected = 0.0; result = list0.averageGPA(); displayResults(result==expected, "average GPA in an empty list"); result = list1.averageGPA(); expected = 6.7; displayResults(Math.abs(result-expected) //TODO: add more tests here } public static void testHighestGPA() { System.out.println(" Starting programAverage tests"); /* List contents: list0: empty list1: v00123:6.7:Geography list2: v00123:6.7:Geography, v00246:9.0:Geography, v00357:8.2:Mathematics list3: v00123:6.7:Geography, v00555:7.8:Physics, v00987:4.5:Psychology, v00246:9.0:Geography v00357:8.2:Mathematics, v00149:7.2:Physics, v00001:8.4:Geography */ Student result = null; Student expected = null; result = list0.highestGPA(); displayResults(result==expected, "highest GPA student in empty list"); result = list1.highestGPA(); expected = new Student("v00123", 6.7, "Geography"); displayResults(result.equals(expected), "highest GPA student in list1"); //TODO: add more tests here }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started