Question
JAVA Project serializable sorted doubly linked list: Your program must be placed in package cs.list You need to implement four classes and a demo program:
JAVA Project serializable sorted doubly linked list:
Your program must be placed in package cs.list
You need to implement four classes and a demo program:
Person
Student
Node
SortedDblList
Demo
Person:
The Person class should implement the generic Comparable
Person's first name (String)
Person's last name (String)
Person's id number (4-digit integer)
Person's date of birth (Date)
public String toString(): This method method should return the following string (without ) for a student with id=1111, firstName="Joe", lastName="Smith", dob="01-25-1990": 1111 Joe Smith 01-25-1990
The Person class should implement all getter and setter methods for these data members, and the compareTo method of the above Comparable interface. The comparsion must be based on the id of the Person instances.
Student:
The Student class is a subclass of Person. It should contain a String attribute that holds the student's college name. It should also contain the proper toString method to add college name (in brackets) to the result of Person.toString() . So, for the above example if "Joe Smith" is a student at "Art&Sci" college. The output of the toString method should be: 1111 Joe Smith 01-25-1990 [Art&Sci]
Node:
The Node class should be generic (let us say the type variable is T), and contain:
a reference of type T called data
reference to the previous Node called prev
a reference to the next Node called next
prev and next should reference the respective nodes in the SortedDblList (making this a doubly linked list).
Demo:
The Demo program is a class with a main method that demonstrates that every method of your SortedDblList works. For the methods union and intersection of SortedDblList show that they work even if the current SortedDblList is a SortedDblList of Persons and the otherList is a SortedDblList of Students (see below). Do not forget to deomnstrate how to serialize (to a file) and deserialize a SortedDblList.
SortedDblList:
The SortedDblList class is a serializable sorted doubly linked list that does not allow duplicates or null elements. The class should contain:
an integer size representing the number of items in the list
a reference of type Node for the head (first node) of the list which is initially set to null
a reference of type Node for the tail (last node) of the list which is initially set to null
a saveListObjects(...) method: should write the value of size and then each element (but not nodes!) of the list to the given stream.
a loadListObjects() method: should read the value of size and then each element of the list from the given stream and add them to the list.
The class should always maintain sortedness of the list based on the result of the compareTo method implemented in the underlying object (in this case it will be based on the person's ID in the Person class). Since we are using the compareTo method, this class should be generic in the sense that it works for ANY T object that implements Comparable
NOTE: PLEASE DESIGN TACH METHOD AND WRITE/DRAW TXAMPLES BEFORE IMPLEMENTING THE FOLLOWING METHODS! IT WILL SAVE YOU MUCH TIME, AND PREVENT FRUSTRATION!
You should also implement the following methods in the SortedDblList class:
/* Returns the element at the specified position in this list. Parameters: index - index of element to return. Returns: the element at the specified position in this list. Throws: IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()). */
public T get(int index);
/* The add method will take an instance of the type variable T as the parameter element, and it will insert it at the correct place within the list using element's compareTo method. This method should not allow null elements or duplicates be added to the list. The method returns true if successful and false otherwise. Therefore, the method does NOT throw exceptions in case the argument is null or the element already exists in the list. */
public boolean add(T element);
/* The remove method removes the first item with its id matching the ID value of the parameter o, and returns true if this list contained the specified element. This method should return false if the item is not found! REMEMBER: Use the equals method to find the item to remove! You implementation of equals should use the compareTo method. If this list does not contain the element, it is unchanged. More formally, the method removes the element with the lowest index i such that get(i).equals(o) == ture. */
public boolean remove(Object o);
/* The isEmpty method returns whether or not the list is empty (true or false) */
public boolean isEmpty();
/* The union method returns a new SortedDblList that is the union of the current list and otherList while maintaining sortedness. */
public SortedDblListunion(SortedDblList extends T> otherList);
/* The intersection method returns a new SortedDblList that is the intersection of the current list and otherList while maintaining sortedness. */
public SortedDblListintersection(SortedDblList extends T> otherList);
/* The printList method will print all elements of the list to the screen; one element per line. That is, for each element of the list it should call the toString method of the element, and then append a newline character to the result, and print the result to the screen. As an example, a list of two Integers 3 and 4 should be printed to the screen as follows: 3 4 */
public void printList();
/* Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element. More formally, returns the lowest index i such that get(i).equals(o) == true, or -1 if there is no such element. */
public int indexOf(Object o);
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