Answered step by step
Verified Expert Solution
Question
1 Approved Answer
[Java] Please test your code in the link I provide before you post your answer. The output should be looked like exact same as the
[Java] Please test your code in the link I provide before you post your answer.
The output should be looked like exact same as the tester.
http://www.codecheck.it/files/1703312307312t8ksnyxnmuwb2vycnwwoos
Use the following files:
RosterTester.java
public class RosterTester { public static void main(String[] arg) { Roster myClass = new Roster(); System.out.println(myClass.getNames()); System.out.println("Expected: []"); myClass.remove("Thomas"); System.out.println(myClass.getNames()); System.out.println("Expected: []"); myClass.add(new Student("Carlos", 3.85)); myClass.add(new Student("Predeep", 3.55)); myClass.add(new Student("Aman", 3.5)); myClass.add(new Student("Amy", 3.95)); myClass.add(new Student("Yen", 3.5)); System.out.println(myClass.getNames()); System.out.println("Expected: [Aman, Amy, Carlos, Predeep, Yen]"); myClass.add(new Student("Predeep", 2.0)); myClass.add(new Student("James", 3.6)); System.out.println(myClass.getNames()); System.out.println("Expected: [Aman, Amy, Carlos, James, Predeep, Predeep, Yen]"); myClass.remove("Fred"); myClass.remove("Predeep"); System.out.println(myClass.getNames()); System.out.println("Expected: [Aman, Amy, Carlos, James, Predeep, Yen]"); } }
Student.java
/** * Models a student in a class room * @author kathleenobrien * */ public class Student { private String name; private double gpa; /** * Constructs a Student with the given name and gpa * @param theName the name of the Student * @param thegpa the gpa of the Student */ public Student(String theName, double thegpa) { name = theName; gpa = thegpa; } /** * Gets the name of this Student * @return the name of this Student */ public String getName() { return name; } /** * Gets the gpa of this Student * @return the gpa of this Student */ public double getgpa() { return gpa; } @Override public String toString() { String s = "[" + getClass().getName() + ":" + "name="+ name + "," + "gpa=" + gpa + "]"; return s; } }Write a class Roster that manages a LinkedList of student objects. The student objects are arranged alphabetically by name. You are given a student class. Do not modity it. The constructor for a Roster has no parameters but initializes an empty LinkedList of Students. The list is the instance variable. Provide these methods: add (Student s) adds the Student to the LinkedList. The Students are maintained in alphabetical order by name remove (string name) removes the first Student with the given name get Names returns an ArrayList of Strings containing the names of a the Students
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