Starting from:

$29

Project # 4 Generic Linked-list-based List ADT


Learning Objectives
• Understand the Use of Iterators in Traversin Linear ADTs.
• More on Understanding References, Objects and Their Manipulation.
• More on Writing Generic Classes and Interfaces
In Lecture # 18 & #20, we introduced code for a doubly-linked list with
iterator. The code mimics the LinkedList class in the Java standard library.
Many of the methods were discussed in class; some methods were, however,
not implemented. In this project, you will implement some of the methods
not implemented and you will add a method to sort the list.
First, look at the Method Summary of the ListIterator provided in the
standard Java API at the sun website:
https://docs.oracle.com/javase/8/docs/api/java/util/ListIterator.html.
Convince yourself that we have signatures for all but two of the methods
listed in that interface in our ListIteratorAPI discussed in class. Add these
signatures to the ListIteratorAPI interface with appropriate documentation:
int nextIndex()
Returns the index of the element that would be
returned by a subsequent call to next.
int previousIndex()
Returns the index of the element that would be
returned by a subsequent call to previous.
Read the details of these methods in the Method Detail section at the url
above. After, you have added these signatures to the interface, define these
methods in the ListIterator class which is a nested class in the List class.
Duncan 1 Fall 2015
Completing A List CSc 1351: Programming Project # 4
Second, see the Method Summary section of the LinkedList API at this url:
https://docs.oracle.com/javase/8/docs/api/java/util/LinkedList.html.
You will observe that only a subset of these methods have been implemented
in the List class we discussed in class. Define the following additional methods
in the List class (wherever an exception is required, use the standard Java
exception class given in the API to report the exception.):
boolean add(E o)
Appends the specified element to the end of this list.
void add(int index, E element)
Inserts the specified element at the specified
position in this list.
void addLast(E o)
Appends the given element to the end of this list.
E element()
Retrieves, but does not remove, the head (first element)
of this list.
E get(int index)
Returns the element at the specified position in this
list.
E getLast()
Returns the last element in this list.
E peek()
Retrieves, but does not remove, the head (first element)
of this list.
E poll()
Retrieves and removes the head (first element) of this
list.
E remove()
Retrieves and removes the head (first element) of this
list.
E remove(int index)
Removes the element at the specified position in this
list.
E removeLast()
Removes and returns the last element from this list.
E set(int index, E element)
Replaces the element at the specified position in this
list with the specified element.
Read the details of these methods in the Method Detail section of the LinkedList
class at the url above. After you have done so, define these methods in the
List class.
Duncan 2 Fall 2015
Completing A List CSc 1351: Programming Project # 4
Augmented Client Program
You will augment the client program in the lecture notes to test the additional
methods you added. Do the following tasks at the end of the main method:
1. Add two statements to print the next and previous indices of the iterator of the
staff List.
The previous index is ....
The next index is ...
2. Using the boolean add method you defined in the list class, add ”Pace” to the end
of the list.
3. Using the position based add method from the list class, add ”Dose” so that it is
the second name of the staff list.
4. Using the addLast method, add ”Apperson” to the end of the list.
5. Using the element method, print the name currently at the head of the list and
using the size method, print the number of names of the list:
The name currently at the head of the list is ......
There are .... names on the list.
6. Using the get methods and index where appropriate, print the fourth and last names
on the list:
The fourth name on the list is .......
The last name on the list is .........
7. First use the poll method to remove and print the element at the head of the list.
Then print the element at the head of the list, this time, using the peek method:
The name at the head of the list is ....
Now, the name at the head of the list is ....
8. Using the remove methods and appropriate index where appropriate, remove the
first and last names from the list and print them:
..... has been removed from the head of the list.
.... has been removed from the tail of the list.
Duncan 3 Fall 2015
Completing A List CSc 1351: Programming Project # 4
9. Using the set method and appropriate index, change the second name of the staff
list to ”Tureau”.
10. Just as is currently been done in the client program in the lecture notes, print the
current list forward and backward. Again, use the size method to print the number
of names in the list.
Forward version of the list is:
...
...
...
Backward version of the list is:
...
...
...
There are .... names still on the list.
Additional Requirements
Do not change the signature of any method or rewrite methods unless indicated in this
handout. Add missing Javadoc where required. Methods that are defined in the interface
will inherit the Javadoc when implemented in the ListIterator inner class so they need not
be documented.
Write header comments for each class and interface using the following Javadoc documentation template:
/**
* Explain the purpose of this class; what it does <br
* CSC 1351 Project # 4
* @author YOUR NAME
* @since DATE THE CLASS WAS WRITTEN
*/
Run the Javadoc utility to make sure that it generates documentation for the List and
ListException classes and the ListIterator Interface. Also, remove all auto-generated Netbeans comments. Locate your source files, List.java, ListIterator.java, ListException and
ListDemo.java, and enclose them in a zip file, YOURPAWSID proj04.zip, and submit your
programming project for grading using the digital dropbox set up for this purpose.
Duncan 4 Fall 2015

More products