Download CS4700 Program 7

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
CS4700 Program 7
Java Pointers, Exceptions, and Javadoc
Background
Javadoc is a Java tool that takes Java class files and generates developer documentation.
To see what javadoc does, do the following.
Download the tree.zip files from the webpage. From the command line (at the directory
containing Tree.java, TreeNode.java, TreeTest.java, type
javadoc *.java
This will create (among other files) index.html. From a browser, select “File/Open File”
and then select the path to index.html. You will see the documentation for these files.
Examine the source files to see the syntax of javadoc commands.
Study the code for manipulating trees in java. Particularly notice the following:
1. You can’t change the actual reference passed to a method (as that would only
change the value of the pointer locally).
2. You can, however, change the contents of the class pointed to.
3. This is an application, so there is no corresponding html file.
4. There is no graphical user interface.
The Assignment
You are to write the Java code to manipulate a linked list. While there are dozen of
instances of a linked list implementation on the web (or from other sources), you are
NOT to look at them. Your linked list must handle integers, but you can write it so any
type can be stored (if you want). Let the tree example be your inspiration for how to
handle pointers in Java, but write the linked list implementation yourself.
There are three exceptions which must be thrown by various methods. These are
supplied in the zip file.
You need to implement the following methods of List. Use Javadoc format to explain all
methods and their parameters:
 public int size(); return number of elements in the list
 public boolean isEmpty();return true if the list is empty, false otherwise.
 public int first() throws EmptyContainerException; Returns the first element in
the list. Throw an exception if there is no first element. Note, in the catch block
you can access the message which is thrown by e.







public void remove (int p) throws NotFoundException; Remove item with
value p from the list.
public int removeLast() throws EmptyContainerException; Remove (and
return) the last item in the list. Throw exception if there is no item to delete.
public void insertAtRank (int rank, int newElement); Insert the newElement at
the position in the list indicated by rank (rank=0, means insert at beginning,
rank=4 means to insert between the fourth and fifth element). If rank>list.size(),
add to the end of the list.
public int next() throws BoundaryViolationException;Returns the next item in
the list. Note, you will need a class variable which keeps track of where you are
in the list. This class variable is set by “first()” and modified by “next()”. This
variable is used by “isNext().” Throws BoundaryViolationException if there is
no next element.
public boolean isNext(); returns true if there are more items in the list which you
have not looked at via next.
public String toString(); return the contents of the list in printable format
Any other methods you need/want to implement.
Modify the ListTest.java file to do the following:
1. Count the number of odd elements in list. Print this value in a readable format
(label your output so we can tell what you have printed).
2. Remove the last three elements and then print list.
3. Print the number of elements in list in a readable format.
4. Insert the value 0 at every third position (rank = 2,5,8,…) in the list. Print the list.
5. Create list2 which is the reverse of the current list (after all the preceding
changes). Print list2 in a readable format.