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.

  • 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.
  • 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.
  • 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.
  • 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 writeintheEvacueeclass. TheEvacueeQueueclassisprovidedtoyouwiththeassignment. You should not implement the EvacueeQueue class, or change its implementation. You must use the EvacueeQueue class as provided.
  • 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.

  • 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 isanintegerbetween0and150. ThethirdlinecontainsaString(MaleorFemale),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.
  • 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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.