Lab 3: Top Ten List
Objectives. The objectives of this lab are:
- To complete the implementation of a singly-linked list class.
- To implement a singly-linked subclass that is used to maintain a top-ten list.
Part I: Implementing and Testing SLinkedList
Source
Goodrich and Tamassia, 4E, § 3.2.
Download the partially implemented definition of Node.java
and SLinkedList.java. We discussed these classes
during lecture.
Implement and test the following methods, which are given in stub form.
- addLast(Node) -- insert Node at the end of the list. This method should
work for empty list, singleton list, and all other cases. (See. p. 119)
- removeLast(): Object -- remove the last node from the list and return its
element. This method should throw
and exception if the list is empty.
- removeNode(Object o) -- remove the node whose element equals the parameter's element.
This method should just do nothing if the element is not found.
Suggestions
- Use stepwise refinement.
- Make sure you adequately test your methods. In addition to
testing the typical case, you need to test all special cases.
Part II: Implementing and Testing the TopTenList Class
Download the partially implemented TopTenList.java
and complete the stub method add(Node). This method should insert a Node
into the list in non-increasing order. For example, if Node contains an Integer
element, then the list will be maintained in non-increasing order:
Size= 10: 875 856 804 789 785 693 693 542 531 520
The TopTenList should never exceed 10 elements. Use (and/or modify) the
main() program to test your implementation.
Part III: Optional Challenge
Modify your implementation so that you can store a game score in the
top-ten list.
Define a GameScore object that consists of an
Integer representing the player's score, and a
String representing the player's name.
This class should implement the Comparable interface,
which contains one method, compareTo(Object):int. This method
would be used as follows:
obj1.compareTo(obj2)
It should return a negative number if obj2 is less than obj1. It should
return 0 if obj1==obj2, and it should return a positive integer if obj2 is
greater than obj1.
Challenging: . Implementing this class will require you to deal with various cast
operations.
Documentation Requirements
All of the methods in your program should contain Javadoc documentation
of the method's parameters and return values. This applies to all code you write
in this course. Use the partial programs as examples for style and format.
You're done. Great work!