Question
Java and please complete the first picture questions by using the student.java codes and tester codes thank you! public class Student { private String sID;
Java and please complete the first picture questions by using the student.java codes and tester codes thank you!
public class Student { private String sID; private int grade; public Student() { sID = ""; grade = -1; } public Student(String sID, int grade) { this.sID = sID; this.grade = grade; } /* Purpose: returns this Student's sID * * Parameters: none * * Returns: String - the sID * */ public String getSID() { return this.sID; } /* 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 grade * * Parameters: none * * Returns: int - the sID * */ public int getGrade() { return this.grade; } /* * * Purpose: set's this Student's grade to grade parameter value * * Parameters: int - grade * * Returns: nothing * */ public void setGrade(int grade) { this.grade = grade; } /* * * Purpose: returns a String representation of this Student * in the form "sID:grade" * * Parameters: none * * Returns: String - the representation * */ public String toString() { return sID + ":" + grade; } /* * * Purpose: returns true if this Student's sID * equals other Student's sID * * Parameters: none * * Returns: boolean - true if equal, false otherwise * */ public boolean equals(Student other) { return (this.sID.equals(other.sID)); } } public class Lab4Tester { private static int testPassCount = 0; private static int testCount = 0; // for approximate comparison of floating point numbers private static final double THRESHOLD = 0.01; public static void main(String[] args) { testNode(); testList();
System.out.println("Passed " + testPassCount + "/" + testCount + " tests"); } public static void testNode() { Student s0 = new Student("abc", 50); Student s1 = new Student("def", 56); Student s2 = new Student("xyz", 99); Student s2b = new Student("xyz", 29); StudentNode n0 = new StudentNode(s0); // must use == to determine whether they are the SAME object, // .equals will tell us if they are equivalent sIDs displayResults(n0.getData() == s0, "test contructor 1 arg with getData"); displayResults(n0.getNext() == null, "test contructor 1 arg with getNext"); StudentNode n1 = new StudentNode(s1, n0); displayResults(n1.getData() == s1, "test contructor 2 args with getData"); displayResults(n1.getNext() == n0, "test contructor 2 args with getNext"); StudentNode n2 = new StudentNode(s2, n1); displayResults(n2.getData() == s2, "test contructor 2 args with getData"); displayResults(n2.getNext() == n1, "test contructor 2 args with getNext"); displayResults(n2.getNext().getNext() == n0, "test contructor 2 args with getNext"); n2.setData(s2b); displayResults(n2.getData() == s2b, "test setData with getData"); n2.setData(s1); displayResults(n2.getData() == s1, "test setData with getData"); n2.setNext(n0); displayResults(n2.getNext() == n0, "test setNext with getNext"); displayResults(n2.getNext().getNext() == null, "test setNext with getNext"); } public static void testList() { // ToDo: add tests to see if your StudentList methods are correct // }
public static void displayResults (boolean passed, String testName) { /* There is some magic going on here getting the line number * Borrowed from: * http://blog.taragana.com/index.php/archive/core-java-how-to-get-java-source-code-line-number-file-name-in-code/ */ testCount++; if (passed) { System.out.println ("Passed test: " + testName); testPassCount++; } else { System.out.println ("Failed test: " + testName + " at line " + Thread.currentThread().getStackTrace()[2].getLineNumber()); } }
}
public interface Student List { Purpose: adds Students to back of this list * Parameters: Student - s * Returns: nothing public void add (Student s); * Purpose: returns the number of elements in this list * Parameters: none * Returns: int - the number of elements public int size(); * * Purpose: returns a String reprensentation of the elements in this list separated by newlines * Parameters: none * Returns: String - the representation */ public String toString(); * Purpose: removes the first element in the list * Parameters: none * Returns: nothing public void removeFront(); * Purpose: determines whether a Student which is equivalent to s is contained in this list * Parameters: Student - S * Returns: boolean - true if a Student matching s is found, false otherwise public boolean contains (Student s); } public interface Student List { Purpose: adds Students to back of this list * Parameters: Student - s * Returns: nothing public void add (Student s); * Purpose: returns the number of elements in this list * Parameters: none * Returns: int - the number of elements public int size(); * * Purpose: returns a String reprensentation of the elements in this list separated by newlines * Parameters: none * Returns: String - the representation */ public String toString(); * Purpose: removes the first element in the list * Parameters: none * Returns: nothing public void removeFront(); * Purpose: determines whether a Student which is equivalent to s is contained in this list * Parameters: Student - S * Returns: boolean - true if a Student matching s is found, false otherwise public boolean contains (Student s); }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