Copyright RIT 2008
$Id: writeup.xml,v 1.17 2010/06/10 23:51:57 vcss233 Exp $

Saving Private Woolie
BattleFront is a
priority queue (created by WoolieWar) which keeps the Woolies sorted based on their military rank and id (from lowest to highest). There is one warmonger who is responsible for fighting the
war, and therefore takes Woolies off the BattleFront (from the front),
and places them into the war (which sadly translates into an untimely death
for each unfortunate Woolie).
Once the death toll passes an acceptable limit, the WoolieWar class
declares a truce and all the the threads naturally terminate -
followed by a report of the final war statistics.
Review your class notes on linked data structures, especially queues and linked list insertion.
If you are unfamiliar with Java's enumerated data type, read the tutorial at http://java.sun.com/docs/books/tutorial/java/javaOO/enum.html. Also review the javadoc for the Enum class.
This lab requires you write a generic class. If you need to review this topic check out the tutorial at http://java.sun.com/docs/books/tutorial/java/generics/index.html.
Download and unpack the jar file that contains the code you will need to complete this lab.
Study the supplied classes and become familiar with the class documentation, ./docs, and the following class diagram.

WoolieWar Class Diagram
Using your schedule, register with the try database.
To register with try, open a terminal window and from a Unix prompt type the following command:
|
If you make a mistake entering either your lecture or lab section, notify your lab instructor right away. They can correct the database before you submit any future work.
For this activity, you must write the Woolie class from scratch and test it. The javadoc contains all the information you need to write the class. Make sure to review the Java coding standard, http://www.cs.rit.edu/~fyj/java-coding-standard.html, and refamiliarize yourself with RCS, http://www.cs.rit.edu/~vcss232/Labs/lab01/Auxiliary/rcs.html
Each Woolie has a unique id (starting at 1), and a military ranking.
The military ranking is represented by the enumerated type
Woolie.Ranking. The ranks
from lowest to highest are: PRIVATE, CORPORAL, SERGEANT, LIEUTENANT,
CAPTAIN, MAJOR, COLONEL, GENERAL.
Internally, each rank has an integral value (starting at 0)
which indicates its position in the declaration. Using the
Enum's compareTo method you can
compare the ranks to determine a Woolie's
natural ordering.
The javadocs can be confusing regarding what you need to write
to make the Ranking Enum. It should just be
defined inside the Woolie class as:
|
You should make a test program for your Woolie class
that creates various Woolies of differing ranks,
and makes sure they display and compare correctly
(based on the javadocs).
Please write your test code in the
main method of the Woolie
class. Part of your grade will be
based on how well your code tests the class.
When you have completed the Woolie class, tested it, and are sure that your code works properly, submit your work by typing the following command:
|
For this activity, you must write the BattleFront class from scratch and test it. Pay careful attention to the javadoc for this class and especially its declaration:
|
Here T is the generic type the collection holds. It
implementes the generic IQueue interface.
Also, because the enqueue method places each element
in the queue based on its natural ordering, it is necessary
that we tell the compiler that class T must
implement the generic Comparable interface.
Internally the collection must be represented as a series of
generic Node structures. Remember
that you always dequeue from the front of the queue,
and you enqueue by traversing through the queue
and finding the location where the element follows the
rules of natural ordering (i.e. all predecessors must compare
less than (or equal) to this element, and all successors
must compare greater than (or equal) to this element.
Because multiple threads might access this collection at the same
time, it is important that you synchronize the
enqueue and dequeue methods. Otherwise
it is possible the collection could get corrupted. Note that it
is not necessary to synchronize the other methods because they
do not modify the collection and the information a thread gets
back is correct for when it was invoked.
Remember that your output will be different each time you run
the WoolieWar program (including the number of
Woolies that get created) because of the threading and randomization.
Take a look at this ./Auxiliary/output.txt
sample run. You can tell it is working correctly because
of the following:
55, i.e.: RECRUITER 0: enlisting COLONEL Woolie(55)
retire message they total: 17 + 17 + 21 = 55.
50 + 5 = 55.
When you have completed the BattleFront class, tested it, and are sure that your code works properly, submit your work by typing the following command:
|
The try program will run your program and save its output each
time you submit. Because of this you will see a significant delay
(usually around a minute) between when you initiate the try
command and when it completes.
Grade Breakdown: