CMSC 202 Project 5

Ships

Assigned Monday May 4, 2009
Program Due 8:00AM, Wednesday May 13, 2009
Weight 10%
Updates 07 May - Compiler issue
There appears to be a difference between the compilers used under Eclipse and on GL.
The 1.6.0 compiler on Linux issues a compiler error on this line which is suggested in the project description
ship.load( (T) cargo );
The easiest fix seems to be to create the Cargo object as type Object, rather than type Cargo.
In other words, instead of
Cargo cargo = new Cargo(....);
ship.load( (T) cargo );
do this
Object cargo = new Cargo(....);
ship.load( (T) cargo );
The compiler doesn't seem to mind casting an Object as type T, but isn't happy casting a Cargo or Person as type T.
Of course do the same thing for loading a Person
This seems to work on Linux and also on Eclipse using compiler 1.6 or 1.5 compatibility

Objectives


Project Description
Ships carry "things" like cargo, people, and oil from one port to another. All ships have the same basic behaviors -- dock at a port, launch from a port to start a new journey, load items, unload items, etc., -- regardless of what kind of "thing" they are carrying. Because all ships have the same behaviors, it is appropriate to design and implement a generic ship class. In this project, the generic ship will be used as both a cargo ship and a cruise ship.

In this project you will use text file I/O to read commands from a file. These commands will tell your ship what functions to perform. Output will be written to a logfile.

You will also be designing and using your own exception classes. The conditions under which an exception is thrown are listed in the details below.

Project 5 is invoked with the following command line arguments in the order listed here.

  1. the type of ship -- "cargo" or "cruise" (without the quotes)
  2. the name of the ship's port of origin
  3. the ship's minimum speed in knots
  4. the ship's maximum speed in knots
  5. the maximum number of items the ship can carry (regardless of any attributes of the items)
  6. the name of the command file
  7. the name of the file to which command output and error messages are logged
You may assume that the command line arguments are of the apporpriate type, integers are positive, and that the speeds are consistent (i.e. max >= min).

Your Tasks

Given the limited time available for this project, some of the code has been written for you. The provided code handles the non-OOP tasks such as reading command line arguements and opening and closing files. Some basic code for some classes is provided as is some of the more difficult syntax for class and method declarations. The remaining tasks that you must complete are listed below.
  1. Copy all the .java files from Mr. Frey's public directory.
  2. Read the description of the command file and the requirements section below.
  3. Based on those descriptions complete the ProcessComands( ) method in Project5.java. This method reads the command file, calls an appropriate method of the Ship and writes the result to the logfile. Be sure to use good top-down design.
  4. Complete the Cargo and Person classes by implementing the methods in the Transportable<T> interface.
  5. Implement the Ship class.
  6. Implement the TransportException class. This is the only exception class required and the only exception class that should be caught in main( ). Methods that throw the TransportException class should construct the class with an appropriate message.
The Command File
For this project, the orders for the ship will be read from a file, the name of which is a command line argument. Each command and each data item will be on a separate line in the command file. The format of the PRINT, DOCK, LAUNCH, SPEED, and QUIT commands are identical for all types of ships. The format of LOAD and UNLOAD are different for each type of ship because cargo and people have different attributes. City names, person names, and unique cargo labels may be multi-word strings. Commands and unique government-issued people IDs do not contain spaces.
  1. PRINT -- Outputs the state of the ship to the log file. Attributes must be output in the order shown below
    1. the ship's minimum speed
    2. the ship's maximum speed
    3. the ship's current speed
    4. the maximum number of items the ship can hold
    5. the ship's current position (ie. travelling from HERE to THERE or in port at CITY)
    6. details of each "thing" being transported, or an apporpriate message that the ship is empty
      • Cargo items are listed in sorted order by their unique label. All attributes of the cargo item must be listed on the same line.
      • People are listed in sorted order by their unique government-issued ID. All attributes of the person must be listed on the same line.
  2. DOCK -- the ship reaches its destination and is tied to the dock, ready for loading or unloading
    The contents of the ship are NOT unloaded.
  3. QUIT -- indicates the end of the command file. Your program exits gracefully.
  4. LAUNCH <port> -- the ship begins travelling to the specified port at its minimum speed
  5. SPEED <new speed> -- the ship changes its speed to the new speed
  6. The formats for LOAD and UNLOAD are different for each type of "thing" the ship is carrying

  7. LOAD
    1. a ship carrying cargo: LOAD <unique cargo label> <weight> <height> <width> <length>
      where the label is a string, and the other attributes are integers. The unit of measure for weight, height, width, and length is irrelevant.
    2. cruise ship carrying people : LOAD <Person name> <age> <Unique government issued ID>
      where the name and ID are strings, and the age is a reasonable positive integer.
  8. UNLOAD
    1. ship carrying cargo: UNLOAD <unique cargo label>
    2. cruise ship carrying people: UNLOAD <unique government issued ID>
The Logfile File
All required output and error messages from all commands must be written to the logfile. The name of the logfile is a command line argument. The required output is described in the command file section above.
Exception Conditions
Your code must handle the following exception conditions.
  1. If an attempt is made to load an item onto a full ship, log an appropriate message and continue to the next command in the file.
  2. If the ship is commanded to travel too fast or too slow, log an appropriate error message and continue to the next command in the file
  3. If an attempt is made to unload a non-existent "thing", log an appropriate message and continue to the next command in the file.
  4. If the ship is commanded to do something that makes no logical sense given its current state, (e.g. change speed while in port) the command should be disregarded (but still logged), an error message should be logged, and the next command read from the file.

Requirements, Hints, Restrictions, and Assumptions

  1. Mr. Frey's public directory for this project is afs/umbc.edu/users/f/r/frey/pub/202/Proj5
  2. A sample command file and the resulting logfile are available in Mr. Frey's public directory.
  3. (Assumption) There are NO weight or volume restrictions when loading "things". The only restriction is on the number of items loaded
  4. (Assumption) You may assume that all command file data is valid. In particular this means
    1. The format of the command file will be valid as specified above
    2. The values of all data in the command file will be valid (e.g. positive)
    3. The command file will contain no invalid commands
    4. All command parameters in the file will be the appropriate type (e.g. no Strings when an int is execpted).
    It DOES NOT mean that all commands make common sense. See Exception Conditions above.
  5. (Requirement) All commands and their parameters must be logged to the logfile as they are being executed, even if the command is not actually carried out.
  6. (Hint) When using Eclipse to develop and test your code, the command file must be located in the base directory for your project at the same level as the src directory. The logfile will be created here as well.
  7. (Requirement) Appropriate top-down design for main( ) and its helper methods is required.
  8. (Hint) The Java Collections library provides a static method named Collections.sort( ) can be used to sort your cargo and people.
  9. (Hint) When passing a Cargo object or Person object to your Ship's load( ) method, it will be necessary to cast it to type T as in ship.load( (T)cargo );
  10. Sanity Check: How much code in your ship class, cargo class, and person class would have to change if a third kind of "thing" to be carried (say barrels of oil) were added to this project? If the answer isn't "NONE!!" then you're doing something wrong.

Project Policy
This project is considered an CLOSED project. This means
  1. You should try as much as possible to complete the project by yourself.
  2. You may get assistance only from the TAs or instructors
  3. You must document all outside help you get as part of your file header comment.
As usual, you MAY NOT
  1. copy anyone else's code
  2. have someone else write your code for you
  3. submit someone else's code as your own
  4. look at someone else's code
  5. have someone else's code in your possession at any time
Such offenses are violations of the student code of academic conduct.
Grading
See the course website for a description of how your project will be graded.
Project Submission
The order in which the files are submitted doesn't matter. However, you must make sure that all files necessary to compile your project are listed. You need not submit all files at the same time. You may resubmit your files as often as you like, but only the last submittal will be graded and will be used to determine if your project is late. For more information, see the projects page on the course website.

You can check to see what files you have submitted by typing

submitls cs202 Proj5

More complete documentation for submit and related commands can be found here.

Remember -- if you make any change to your program, no matter how insignificant it may seem, you should recompile and retest your program before submitting it. Even the smallest typo can cause compiler errors and a reduction in your grade.

Avoid unpleasant surprises!