Transport Aircraft

AssignedThursday, April 25, 2013
Program DueThursday, May 9, 2013, 11:59pm
Weight10%
Updates

Objectives

To gain experience

Project Description

A transport aircraft carries “things” like cargo, people, and water from one destination to another. A transport aircraft has the same basic behaviors — take off, landing, loading, unloading, etc., — regardless of what kind of “thing” it is carrying. Because all transport aircraft have the same behaviors, it is appropriate to design and implement a generic transport aircraft class. In this project, the generic transport aircraft will be used as both a cargo plane and a commuter plane.

In this project, you will use text file I/O to read commands from a file. These commands will tell a transport aircraft what functions to perform. Output will be written to a log file.

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 transport that will be flown: “cargo” or “commuter” (without the quotes)
  2. The name of the transport's city of origin
  3. The transport's minimum flying altitude
  4. The transport's maximum flying altitude
  5. The maximum number of items the transport can hold (regardless of any attributes)
  6. The name of the command file
  7. The name of the file to which command output and error messages are to be logged

You may assume that the command line arguments are of the appropriate types, integers are positive, and that the flying altitudes are consistent (i.e. maximum ≥ minimum).

Your Tasks

  1. Read the description of the command file and the requirements section below.
  2. Based on those descriptions, design and implement a generic class to model the transport aircraft.
  3. Based on those descriptions, design and implement a class to model cargo.
  4. Based on those descriptions, design and implement a class to model a person.
  5. Write main( ) and all its helper methods in a class named Project5.java.
  6. Design, implement, and appropriately use exception classes to detect and handle error conditions.
  7. Design and implement any other classes you feel are necessary.

The Command File

For this project, the orders for each aircraft 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, LAND, TAKEOFF, CLIMB, DESCEND and QUIT commands are identical for all transport aircraft. The format of LOAD and UNLOAD are different for each type of transport aircraft. City names, person names, and unique cargo labels may be multi-word strings. Commands and unique government-issued IDs do not contain spaces.

  1. PRINT — Outputs the following information to the log file.
    1. The aircraft's minimum and maximum flying altitudes
    2. The maximum number of items the aircraft can hold
    3. The aircraft's current position (e.g. flying from HERE to THERE, on the ground in CITY)
    4. Details of each “thing” being transported in sorted order, or an appropriate message that the aircraft 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. LAND — The aircraft reaches its destination and is parked, ready for loading or unloading. The contents of the aircraft are NOT unloaded.
  3. QUIT — Indicates the end of the command file. Your program exits gracefully.
  4. TAKEOFF <city> — The aircraft begins flying to the specified destination at its minimum flying altitude.
  5. CLIMB <number of feet> — The aircraft increases its flying altitude by the specified number of feet. This is NOT the new flying altitude.
  6. DESCEND <number of feet> — The aircraft decreases its flying altitude by the specified number of feet. This is NOT the new flying altitude.
  7. The formats for LOAD and UNLOAD are different for each type of “thing” the transport aircraft is carrying.

  8. LOAD
    1. Aircraft carrying cargo: LOAD <unique cargo label> <weight> <height> <width> <length>
      where the label is a string, and the other attributes are positive integers. The unit of measure for weight, height, width, and length is irrelevant.
    2. Aircraft 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.
  9. UNLOAD
    1. Aircraft carrying cargo: UNLOAD <unique cargo label>
    2. Aircraft carrying people: UNLOAD <unique government issued ID>

You can see a sample command file here. But please note this is just a sample command file!!!

The Logfile File

All required output and error messages from aircraft commands must be written to a logfile using text file I/O. The name of the logfile is a command line argument. The required output is described in the command file section above. The PrintWriter class can be used to write data to a file.

PrintWriter out = new PrintWriter(new File(filename));

out.printf("%10s%10s%10s\n", "Hello", "Output", "file");
out.printf("%10s%10s%10s\n", "Hello2", "Output2", "file2");
out.printf("%-10s%-10s%-10s\n", "Hello", "Output", "file");
out.printf("%-10s%-10s%-10s\n", "Hello2", "Output2", "file2");
out.close();
All text printed must be neatly aligned. This example neatly aligns each string with 10 (underscore characters) spaces as follows:
_____Hello____Output______file
____Hello2___Output2_____file2
Hello_____Output____file______
Hello2____Output2___file2_____

A sample logfile has been generated based on the sample command file.

Exception Conditions

Your code must handle the following exception conditions. Any other error conditions that your code introduces should also be checked. Be sure to use appropriate exceptions together with try/catch blocks to separate error detection from error handling.

  1. If there are any errors with the command line arguments, display an appropriate error message to the screen or log an error to the logfile and exit your program. You should check that the number of command line arguments is correct and that each of the files can be opened appropriately. (Of course, if the error is that the logfile can't be opened, then the error should be printed to System.out.)
  2. If an attempt is made to load an item onto a full transport aircraft, log an appropriate message and continue to the next command in the file.
  3. If the transport aircraft is commanded to climb too high, log an appropriate error message, level off at the maximum flying altitude, and continue to the next command in the file.
  4. If the transport aircraft is commanded to descend too low, log an appropriate error message, level off at the minimum flying altitude, and continue to the next command in the file.
  5. If an attempt is made to unload a non-existent “thing”, log an appropriate message and continue to the next command in the file.
  6. If the transport aircraft is commanded to do something that makes no logical sense given its current state, the command should be disregarded (but still logged), an error message should be logged, and the next command read from the file.

Requirements, Restrictions, and Assumptions

  1. All classes in this project should be in a package named proj5.
  2. There are NO weight or volume restrictions when loading “things.” The only restriction is on the number of items loaded.
  3. “things” do NOT automatically unload when the transport lands.
  4. 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.
    It DOES NOT mean that all commands make common sense or are valid commands. See Exception Conditions above.
  5. 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. Appropriate object-oriented design is required. As discussed in class throughout the semester, this includes, but is not limited to:
    1. private instance variables only
    2. limited public interfaces for all classes - don't write unnecessary methods
    3. maximum code reuse
    4. use of try-throw-catch for exceptions
  7. Appropriate top-down design for main( ) and its helper methods is required.
  8. Sanity Check: How much code in your transport aircraft 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 a 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, CS Help Center tutors, 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

  1. submit the .java files for all classes you implement. To submit a single .java file (for example, your Project5.java file), do so as follows.
          submit cmsc202 proj5 Project5.java
          

    To submit more than one file at once, simply list them.

          submit cmsc202 proj5 Project5.java Person.java Another.java
          

    To submit all of your .java files at once,

          submit cmsc202 proj5 *.java
          
  2. 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 cmsc202 proj5
    

    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!