I suggest that you start your work with a Sequence.java file with a main method that allows you to test the methods very briefly with manual input, then expand this to a SequenceUI.java that imports methods from Sequence and conducts more elaborate tests. I will provide frameworks for both of these classes. Here (without its methods :-) is the Sequence that I showed in class the other day: click Note that Node is a private class member of Sequence. See examples on page 568 and 578 of the text.
And here is the original assignment: click
----------------------
Sequence API
----------------------
<< constructor >>
returns a Sequence object
+add(item:int):void
adds item to Sequence
so that Sequence is always in
ascending order
+display( ):void
displays items of Sequence on output device
+get(pos:int):int
returns value of item at position pos
+find(k:int):int
returns position of first item having value k
in Sequence
+length( ):int
returns number of items in Sequence
+count(k:int):int
returns number of items having value k in Sequence
+delete(pos:int):void
deletes item at position pos from Sequence
+remove(k:int):void
removes all occurrences of items with value k
+removeAll( ):void
removes all items from Sequence
+equals(s2:Sequence):boolean
returns true if number of items and values of items
in Sequence s2 are same as those of caller
+copy( ):Sequence
returns a deep copy of caller
makes new Sequence object
for each node in caller
make new node
copy value of caller's node
add new node to new Sequence
return the new Sequence
Extra props go to a student who supplies a method that displays the reverse of a Sequence: e.g., the reverse of {1 2 3} is {3 2 1}. The implementation is completely up to the student!
No comments:
Post a Comment