Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Student { private String sID; private int grade; public Student() { sID = ; grade = -1; } public Student(String sID, int grade)

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedpublic 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)); } }

image text in transcribed

public class StudentLinkedList implements StudentList { private StudentNode head; private int count; public StudentLinkedList() { head= new StudentNode (new Student()); count =0; } 0 0 public void add (Student s) { StudentNode newstudent = new StudentNode (s); StudentNode index = head; newstudent.next = null; if(head == null) { head = newstudent; } else while(index.next != null) { index = index.next; } index.next = newstudent; } count ++; } public int size() { return count; } public String toString() { return ""; } public void removeFront() { head = head.next; --counti } public boolean contains (Student s) { StudentNode index = head; while(index !=null) { if(index.equals(s)) { return true; } index = index.next; } return false; } 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 testList() { // ToDo: add tests to see if your StudentList methods are correct // Student so new Student ("abc", 50); Student si new Student ("def", 56); Student 32 = new Student ("xyz", 99); Student 32b = new Student ("xyz", 29); StudentLinkedList nl = new StudentLinkedList(); nl.add(32); displayResults (nl.size() == "test add and size Studnet"); 1 StudentLinkedList n2 = new Student LinkedList(); n2.add(0); nl.add(0); nl.removeFront (); displayResults (nl == n2, "test remove front"); 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 Student s to back of this list * Parameters: Student - * 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); Failed test: test remove front at line 76 public class StudentLinkedList implements StudentList { private StudentNode head; private int count; public StudentLinkedList() { head= new StudentNode (new Student()); count =0; } 0 0 public void add (Student s) { StudentNode newstudent = new StudentNode (s); StudentNode index = head; newstudent.next = null; if(head == null) { head = newstudent; } else while(index.next != null) { index = index.next; } index.next = newstudent; } count ++; } public int size() { return count; } public String toString() { return ""; } public void removeFront() { head = head.next; --counti } public boolean contains (Student s) { StudentNode index = head; while(index !=null) { if(index.equals(s)) { return true; } index = index.next; } return false; } 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 testList() { // ToDo: add tests to see if your StudentList methods are correct // Student so new Student ("abc", 50); Student si new Student ("def", 56); Student 32 = new Student ("xyz", 99); Student 32b = new Student ("xyz", 29); StudentLinkedList nl = new StudentLinkedList(); nl.add(32); displayResults (nl.size() == "test add and size Studnet"); 1 StudentLinkedList n2 = new Student LinkedList(); n2.add(0); nl.add(0); nl.removeFront (); displayResults (nl == n2, "test remove front"); 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 Student s to back of this list * Parameters: Student - * 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); Failed test: test remove front at line 76

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago