Page 1 of 1

PLEASE HELP package sysImplementation; import java.util.ArrayList; import java.util.Collections; public class Roster {

Posted: Fri Jul 08, 2022 6:39 am
by answerhappygod
PLEASE HELP
package sysImplementation;
import java.util.ArrayList;import java.util.Collections;
public class Roster { private class Node { private int id; private Node next;
private Node(int id){ this.id =id; next =null; } } /* List tail pointer */ private Node tail; private String name; private int size; //assume 3 digit id public Roster(String name, int id) { this.name = name; tail = new Node(id); tail.next = tail; size = 1; } // just forms a string with all ids private String ids() { Node temp = tail.next; String idStr =""; int counter =1; while(counter<=size) { idStr+=temp.id+" "; counter++; temp =temp.next; } return idStr; } @Override public String toString() { return "Roster [ids=" + ids()+ ", name=" + name + "]"; }
public int getFirstId() { if(tail==null) { returnnull; } return tail.next; } public int getLastId() { } //assume unique 3 digit id will be passedin public void add(int id) {
} public ArrayList<Integer> getCSIds(){ //at some point you need tocall getCSIdsAux } //Write your own private RECURSIVEgetCSIdsAux
}
Please Help Package Sysimplementation Import Java Util Arraylist Import Java Util Collections Public Class Roster 1
Please Help Package Sysimplementation Import Java Util Arraylist Import Java Util Collections Public Class Roster 1 (506.89 KiB) Viewed 37 times
Roster Class Specification The Roster class represents a roster for a course. The ids will be held in a circular singly linked list. A circular linked list is just like the linked list we talked about in class with the exception that the next reference of tail does not point to null, but instead points back to head (thus the idea of a circle). There is no explicit head field needed since the head is always simply the next of the tail. An empty list would just be the tail pointing to null, a list with one node would have tail point to that node and the next of tail point back to the same node (see the given constructor), a list with two or more nodes would have the tail point to the last node with the next of the last node pointing back to the first node (i.e. the "head" of the list). The details of what you need to implement is given below. You cannot add any extra fields (e.g. an explicit head field). The class has the following fields: private Node tail; private String name; private int size; The field tail points to the last Node of the circular singly linked list that holds the ids of students on the roster, the field name is the name of the course, the field size is the number of nodes in the linked list. The class has the following methods that you need to code: 1. constructor - Make no changes. If you change it, you are going to fail tests. After this code runs, you can assume you have a valid circular singly linked list with one node 2. ids - Make no changes. If you change it, you are going to fail tests. You will never call this method in the code you write. Only used to form a string of ids and called in the toString. 3. toString-Make no changes. If you change it, you are going to fail the majority of the tests. 4. getFirstId - Simply return the id in the first node. 5. getLastId - Simply return the id in the last node. 6. 7. add - You can assume a unique 3-digit id will be passed in. A CS id is an id between 200 (inclusive) and 299 (inclusive). If the id passed in is a CS id, add to the front of the list. If it is a non-CS id, add to the end. If necessary, don't forget to update the node that tail points to. Every time that add is called the size should be incremented by one since it now has one more node. Remember that you never have to handle adding to an empty list since the constructor adds the first node and there is no remove. getCSIds - This method will return an ArrayList of the CS ids found in the circular singly linked list in sorted numeric order. You can use the sort method from the imported Collections class to sort. If there are no CS ids in the list, simply return an empty ArrayList. getCSIds must make ONE call to get CSIdsAux, which is a private recursive method that you will design and write. You can decide what gets passed in or returned (can be void) from getCSIdsAux.