Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

follow instructions in first 2 photos, complete in java Exercise - Interfaces In this lab you will be implementing and testing the StudentNode and StudentLinkedList

follow instructions in first 2 photos, complete in java image text in transcribedimage text in transcribed
image text in transcribedimage text in transcribed
image text in transcribedimage text in transcribed
image text in transcribedimage text in transcribed
Exercise - Interfaces In this lab you will be implementing and testing the StudentNode and StudentLinkedList classes depicted in the following UML diagram. Recall: the dashed arrow implies that one class implements the interface pointed to, the solid line means one class uses the other class. StudentList > + add (Student): void + size(): int + toString(): String + removeFront (): void + contains (: boolean Student SID: String grade: int + Student () + Student (String, int) + getSID(): int + SetSID(String): void + getGrade(): int + setGrade (int): void + toString(): String + equals (Student): boolean 1 StudentLinkedList head: StudentNode count: int + StudenthinkedList() + add (Student): void + size(): int + toString(): String + removeFront) : void + contains (Student): boolean StudentNode + next: StudentNode data: Student + Student Node (Student) + StudentNode (Student, StudentNode) + getNext(): StudentNode + BetNext (StudentNode): void + getData(): Student + Set Data (Student): void 1. Download StudentList.java Lab4 Tester java and Student java to your Lab4 folder 2. Implement the StudentNode class in a new file called StudentNode.java in your Lab4 folder. a Write and test each constructor and method one at a time. b. To test, compile and run Lab4Tester.java 3. Implement the StudentLinkedList class in a new file called StudentLinked List.java in your Lab4 folder a. This class MUST implement the StudentList interface: public class StudentLinkedList implements StudentList {... b. Write and test each constructor and method one at a time. You will need to write tests in the testList method in Lab4 Tester java If you are unsure how to test, look at the testNode method for help and the testShapeList method in Lab3Tester java from last week. public class LabTester { private static int testPassCount = 0; private static int testCount = 0; Il 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"); } 3 4 5 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 EL public static void testNode() { Student se - new Student ("abc", 50); Student si = new Student("def", 56); Student s2 = new Student("xyz", 99); Student s2b - new Student("xyz", 29); StudentNode ne - new StudentNode(se); 1/ must use -- to determine whether they are the SAME object, Il .equals will tell us if they are equivalent SIDS displayResults(ne.getData() -- se, "test contructor i arg with getData"); displayResults(ne.getNext() -- null, "test contructor 1 arg with getNext"); StudentNode ni - new StudentNode(si, ne); displayResults(n1.getData() == $1, "test contructor 2 args with getData"); displayResults(n1.getNext() -- ne, "test contructor 2 args with getNext"); StudentNode n2 = new StudentNode(s2, ni); displayResults(n2.getData() -- s2, "test contructor 2 args with getData"); displayResults(n2.getNext() -- ni, "test contructor 2 args with getNext"); displayResults(n2.getNext().getNext() -- ne, "test contructor 2 args with getNext"); n2.setData(s2b); displayResults(n2.getData() - $2b, "test setData with getData"); n2.setData(si): displayResults(n2.getData() - S1, "test setData with getdata"); n2.setNext(ne); displayResults(n2.getNext() == ne, "test setNext with getNext"); displayResults(n2.getNext().getNext() -- null, "test setNext with getNext"); } public static void testList() { Il 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 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 2 3 4 5 6 7 28 29 30 Parameters: none * Returns: String - the sID */ public String getSID() { return this.SID; 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 Purpose: set's this Student's sid to sID parameter value * Parameters: String - SID Returns: nothing public void setSID(String SID) { this.SID = 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; 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 interface Studentlist Purpose: adds Student s to back of this list Parameters: Students * 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

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

Step: 3

blur-text-image

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

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

2. How will the team select a leader?

Answered: 1 week ago