Sale!

COP 3330 Homework 3 solved

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (1 vote)

COP 3330 Homework 3

Problem: Cruise Ship Evacuation

Titanic Cruise Lines (TCL) has decided that due to an unfortunate incident, it needs to streamline the
evacuation of occupants from a sinking cruise ship.

The old stand-by of “women and children first” was
found to not be sufficiently clear for the prioritization of evacuees, which led to people falling off the ship
and hitting propeller blades and such (a very messy affair). To help reduce the chaos under these stressful
circumstances, TCL has commissioned you along with a team of software engineers to develop a program
to determine the order in which people should be let on to lifeboats.

Priority and Ordering of Evacuees

This whole paragraph is particularly important! Children have the highest priority in being evacuated
from the ship, where a child is defined as a person aged less than 18 years. Among children, the younger
they are, the higher their priority. Children of the same integer age should be prioritized based on their last
names (String comparison).

If two children have the same age and last name, they should then be
prioritized based on first name. Amongst adults (people age 18 and older), women have priority over men.
The executives of TCL, being very wealthy individuals, insist that adults of the same sex be prioritized
based on annual income (wealthier have higher priority).

Finally, adults of the same sex with equal income
should be prioritized by name in the same way as children. There will not be two people with the same
name on one ship.

Program Design and Classes

There are a total of five classes in this program. Two of the classes are already developed and you have to
write the other three.
1. Name: A Name object represents the name of an evacuee or a person. The Name class must
implement Comparable interface. The Name objects are compared base on the above
criteria: last name using String comparison, then break tie using first name if the last names are
identical. You should implement the Name class for this assignment.

2. Money: A Money object represents some amount of money. We developed the Money class in
class. The version of Money class you should use for this assignment is provided with the
assignment. You should use this Money class to represent the annual income of Evacuees. You
should not implement the Money class, or change its implementation. You must use the Money
class as provided.

3. Evacuee: An evacuee on the cruise ship. Each Evacuee object should contain all the
information on a person. In particular, it should have a Name object to represent the Evacuee’s
name and a Money object to represent his/her annual income.

The Evacuee class must
implement the Comparable interface. As such, it must have a compareTo
method that takes in another Evacuee. This .compareTo method should satisfy the standard
compareTo contract and impose a natural ordering based on the priority of Evacuees. That is to
say, if Evacuee x has higher priority than Evacuee y (i.e. x should come before y), then
x.compareTo(y) should return a negative number. If x has lower priority than y, then

x.compareTo(y) should return a positive number. If x and y have equal priority, then
x.compareTo(y) should return 0. The natural ordering of Evacuees, implemented correctly,
should rank Evacuees with higher priority before Evacuees with lower priority. Thus, in a sorted
array the Evacuee with highest priority comes first.

Another important method is the toString
method. The toString method should return a String describing the evacuee using the format
described in the javadoc. It should not print that String to the screen directly. You should
implement the Evacuee class for this assignment.

4. EvacueeQueue: The EvacueeQueue is used for lining up Evacuees base on their priorities
(natural ordering). With an EvacueeQueue object, you can add Evacuees to the queue, or
retrieve (and remove) the Evacuee with highest priority among everyone in the queue. It is
important to note that this “order of priority” is only as good as the compareTo method that you
write in the Evacuee class.

The EvacueeQueue class is provided to you with the assignment.
You should not implement the EvacueeQueue class, or change its implementation. You must
use the EvacueeQueue class as provided.

5. Evacuation: The Evacuation class is where your main method will reside. It should read in
data from Evacuation.in and output to Evacuation.out. You should implement the
Evacuation class.

Along with this assignment description, there is a doc folder which contains detailed documentation of each
of these classes. You should open index.html in the doc folder to get started. You must implement each of
the three classes according to the accompanying javadoc.

This means each of your class must implement
all the constructors and methods stated in the javadoc, whether or not the method is necessary for solving
the problem of this assignment. It is critical that you implement these methods correctly. Even if your
program works fine, you may still get points deducted for faulty methods.
Input (Evacuation.in)

The input file contains a series of commands. There are two types of commands: Add Person and
Release Lifeboat. Your Evacuation class should have a main method that reads from
Evacuation.in, and process each command.

1. Add Person: Following an Add Person command is four lines of input, giving information
about one person. The first line contains the first name, followed a space, and followed by last
name of the person. Both first and last names consist of one or more English letters, with the first
letter capitalized and the rest given in lowercase.

The second line contains the person’s age, which
is an integer between 0 and 150. The third line contains a String (Male or Female), indicating
the person’s gender. The last line contains the annual income of the person, in the format $x.yy,
where x is the amount of dollars and yy is the number of cents, in 2 decimal places. A person
makes between $0.00 and $10000000.00 a year. Note that for the purpose of this problem,
even children and infants may have annual income.

For each Add Person command, the given person should be added to the EvacueeQueue as
an Evacuee. This means you should instantiate an Evacuee object for each Add Person
command. There will not be two people with the same name in the input file.

2. Release Lifeboat: Following a Release Boat command is one line containing the
number of spaces on the boat. Each boat has space for 1 – 20 people. Children, infants and adults
each takes one unit of space on the boat. For each Release Lifeboat command, you should
print out the list of Evacuees going on that boat.

The Evacuees with highest priorities among the
people in the EvacueeQueue get to go on the lifeboat. The Evacuees should be printed base on
priority in order from high to low.

You should process all commands until the end of file. The last command will always be a Release
Lifeboat command.
Output (Evacuation.out)
You should print your output to a file called Evacuation.out. For each Release Lifeboat
command print a heading:
Lifeboat # Evacuees List:

Where is a boat ID, starting from 1 and increments for each boat. Then, there should be zero or
more lines listing evacuees getting on this lifeboat, base on their priorities. This may result in a boat full of
infants, but that’s okay since this is an emergency.

Each Evacuee should be printed using the
toString() method of the Evacuee class as described in the javadoc. You should fill up each boat
either to its full capacity or until everyone added to EvacueeQueue so far has been evacuated.
Then, print two lines stating the number of spaces left on the boat, and the number of evacuees remain
waiting in the queue. Print a blank line after the output for each lifeboat. Follow the exact format of
sample output.

Sample I/O

See Evacuation.sample.in and Evacuation.sample.out for sample input and output. Your
program’s output must match exactly with the sample output in order to receive full credit.

Deliverables

You must submit the 3 source code files (Name.java, Evacuee.java, Evacuation.java) for your
program over WebCourses. You must submit your source files as an attachment using the “Add
Attachments” button. Assignments that are typed into the submission box will not be accepted.
Documentation

Your code must include:

1. Header comments for each source file, with the following information: your name, course number
and date.
2. Description of the functionalities and responsibilities of each class.
3. Comments for each public method and field in your classes.
4. Inline comments throughout the code explaining its logic and design.

Restrictions

1. Your program must compile using Java 6.0 or later.
2. For each of the three classes you write, you must implement all the methods listed in the javadoc
provided, even if a method is not necessary for the assignment problem.
3. Even if your program produces the correct output and match the reference output exactly, you will
incur a significant penalty if your code does not implement the required classes with the required
methods.

Execution and Grading Instructions (This is for TAs)
Points Total: 100

1. First, create an directory and put in it source files EvacueeQueue.java and Money.java.
2. For each student, download student’s source codes Name.java, Evacuee.java and
Evacuation.java into the source directory.
3. Review each of the source files for comments and appropriate methods.
4. Copy Evacuation.sample.in into Evacuation.in, and run the program. Then,
compare output Evacuation.out with Evacuation.sample.out using
FileCompare.java.

5. Repeat step 4 with Evacuation.judge.in and Evacuation.judge.out.
Points Breakdown
Execution: 50
Code: 30
Documentation: 20

COP 3330 Homework 3