Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribed

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 }

public String toString() { return "{" + toStringRecursive (head) + "/"; } public String toStringRecursive (StudentNode cur) { if (cur == null) { return ""; } else if (cur.next == null) { return cur.getData().toString() + toStringRecursive (cur.next); } else { return cur.getData().toString() + ", " + toStringRecursive (cur.next); } } public boolean inProgram (String program) { return inProgramRecursive (head, program); //To do private boolean inProgramRecursive (StudentNode cur, String program) { return false; // so it compiles //To do public Student getStudent (String SID) { return getStudentRecursive (head, ID); //To do private Student getStudentRecursive (StudentNode cur, String SID) { return null; // so it compiles //To do } public double averageGPA() { if (size() == 0) { return 0.0; } else { return sumGPARecursive (head) /size(); } //To do } private double sumGPARecursive (StudentNode cur) { return 0.0; // so it compiles //To do } public double programAverage (String program) { // call a recursive helper method! return 0.0; //To do } public Student highestGPA() { // call a recursive helper method! return null; //To do } public class StudentNode { public StudentNode next; private Student data; public StudentNode (Student data) { this.data = data; this.next = null; } public StudentNode (Student data, StudentNode next) { this.data = data; this.next = next; } * Purpose: returns the value of this StudentNode's next * Parameters: none * Returns: StudentNode - the next public StudentNode getNext() { return this.next; } * Purpose: set's this StudentNode's next to parameter value * Parameters: StudentNode - next * Returns: nothing */ public void setNext (StudentNode next) { this.next = next; /* * Purpose: returns the value of this StudentNode's data * Parameters: none * Returns: Student - the data public Student getData() { return this.data; } * Purpose: set's this StudentNode's data to parameter value Parameters: Student - data * Returns: nothing public void setData (Student data) { this.data = data; } public String toString() { return "{" + toStringRecursive (head) + "/"; } public String toStringRecursive (StudentNode cur) { if (cur == null) { return ""; } else if (cur.next == null) { return cur.getData().toString() + toStringRecursive (cur.next); } else { return cur.getData().toString() + ", " + toStringRecursive (cur.next); } } public boolean inProgram (String program) { return inProgramRecursive (head, program); //To do private boolean inProgramRecursive (StudentNode cur, String program) { return false; // so it compiles //To do public Student getStudent (String SID) { return getStudentRecursive (head, ID); //To do private Student getStudentRecursive (StudentNode cur, String SID) { return null; // so it compiles //To do } public double averageGPA() { if (size() == 0) { return 0.0; } else { return sumGPARecursive (head) /size(); } //To do } private double sumGPARecursive (StudentNode cur) { return 0.0; // so it compiles //To do } public double programAverage (String program) { // call a recursive helper method! return 0.0; //To do } public Student highestGPA() { // call a recursive helper method! return null; //To do } public class StudentNode { public StudentNode next; private Student data; public StudentNode (Student data) { this.data = data; this.next = null; } public StudentNode (Student data, StudentNode next) { this.data = data; this.next = next; } * Purpose: returns the value of this StudentNode's next * Parameters: none * Returns: StudentNode - the next public StudentNode getNext() { return this.next; } * Purpose: set's this StudentNode's next to parameter value * Parameters: StudentNode - next * Returns: nothing */ public void setNext (StudentNode next) { this.next = next; /* * Purpose: returns the value of this StudentNode's data * Parameters: none * Returns: Student - the data public Student getData() { return this.data; } * Purpose: set's this StudentNode's data to parameter value Parameters: Student - data * Returns: nothing public void setData (Student data) { this.data = data; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

(4) C (U + 2102), the set of complex numbers; and

Answered: 1 week ago