Question: public class A4LinkedList implements A4List { // Completed for you, should not be changed private StudentNode head; private StudentNode tail; private int numElements; // Completed

public class A4LinkedList implements A4List { // Completed for you, should not be changed private StudentNode head; private StudentNode tail; private int numElements;

// Completed for you, should not be changed public A4LinkedList() { head = null; tail = null; numElements = 0; } // Completed for you, should not be changed public int size(){ return numElements; } // Completed for you, should not be changed public boolean isEmpty() { return head == null; } // Completed for you, should not be changed public void insert(Student s) { StudentNode n = new StudentNode(s); if (head == null) { head = n; } else { tail.next = n; } tail = n; numElements++; } /* * Purpose: create a string representation of list * Parameters: none * Returns: String - the string representation * * Completed for you, should not be changed */ 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); } private boolean inProgramRecursive(StudentNode cur, String program) { return false; // so it compiles }

public Student getStudent(String sID) { return getStudentRecursive(head, sID); } private Student getStudentRecursive(StudentNode cur, String sID) { return null; // so it compiles } public double averageGPA() { if (size() == 0) { return 0.0; } else { return sumGPARecursive(head)/size(); } } private double sumGPARecursive(StudentNode cur) { return 0.0; // so it compiles } public double programAverage(String program) { // call a recursive helper method! return 0.0; } public Student highestGPA() { // call a recursive helper method! return null; } }

public interface A4List { /***************************************************************** * The first 3 methods are completed for you in A4LinkedList.java * *****************************************************************/ /* * Purpose: get the number of elements in the list * Parameters: none * Returns: int - the number of elements in the list */ public int size(); /* * Purpose: determines whether the list is empty * Parameters: none * Returns: boolean - true if empty, false otherwise */ public boolean isEmpty(); /* * Purpose: inserts a student at the back of the list * Parameters: Student s - the student to insert * Returns: void - nothing */ public void insert(Student s); /**************************************************** * You will need to complete the following 5 methods * ****************************************************/ /* * Purpose: determines whether the list contains * a student in the given program * Parameters: String - the program to search for * Returns: true if a student in the given program is found, false otherwise * Precondition: program is not null */ public boolean inProgram(String program); /* * Purpose: gets a student with the given sID, if the * list contains a student with the given sID * Parameters: String - the sID to search for * Returns: Student - the student if found, null otherwise * Precondition: sID is not null */ public Student getStudent(String sID);

/* * Purpose: get the average GPA of all students in the list * Parameters: none * Returns: double - the average GPA of all students */ public double averageGPA(); /* * Purpose: gets the average GPA of all students in the given program * Parameters: String - the program to search for * Returns: double - the average gpa of all students in the program * Precondition: program is not null */ public double programAverage(String program); /* * Purpose: get the student with the highest GPA in the list * Parameters: none * Returns: Student - the student with the highest GPA */ public Student highestGPA();

}

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 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)); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!