CMSC 202 Project 5
Assigned Monday, Nov 26
Program Due 10:00AM, Tuesday, Dec 11
Design Due 10:00AM Tuesday, Dec 4
Weight 10%
Updates

Objectives

Project Description
In this project you will implement a class to model a delivery truck. Since delivery trucks can carry any type of cargo, it is appropriate to design and implement the truck using Java generics. You will also implement classes to model boxes, cans, and sacks carried in the truck.

Your project will instantiate exactly three delivery trucks -- one that carries boxes, one that carries cans, and one that carries sacks. Your trucks will load boxes/cans/sacks, drive from one destination to another, deliver boxes/cans/sacks, and print an inventory their contents. Commands read from a command file direct your trucks. Output from your project will be displayed on the screen and output to a file.

This project will get its input from the command line rather than from a GUI.
The command linewill have three arguments

  1. The maximum number of boxes/cans/sacks a truck can carry regardless of their size or weight.
  2. The name of the command file.
  3. The name of the output file.


Class Definitions
For this project you will implement a generic Truck class and separate classes for Box, Can, and Sack. You will also implement a class named Project5 whose only purpose is to contain the code for main and main's helper methods.

The Generic Truck Class

Since a truck can carry any kind of package, the truck will be implemented using Java generics.

Our truck has the following attributes. Other private attributes may be added if you find them helpful in your implementation

  1. Its capacity (max number of packages) as read from the command line.
  2. Its current location
  3. The total number of miles driven
  4. A list of the current contents of the truck
Our truck supports the following operations:
  1. Construction of an empty truck. Creates an empty truck with the user specified capacity which has been driven zero miles and begins its journey at a location specified as "Warehouse".
  2. Load an item onto the truck. Duplicate items are permitted.
  3. Deliver an item. Unloads the specified item from the truck. If the item to be unloaded is one of a set of duplicates, unload any one of the duplicate items.
  4. Drive the truck a specified number of miles to a new location.
  5. Other necessary methods such as equals, toString, etc.

The Sack Class

A Sack has the following attributes: its contents (a string ; the material from which it's made (a string); its weight in pounds (a positive integer); and the name of the person to whom it is addressed (another string). A sack is uniquely identified by all of its attributes.

The Box Class

A Box has the following attributes: length, width, height, and weight in pounds (all positive integers), its contents (a string), and the name of the person to whom the box is addressed (another string). A box is uniquely identified by all of its attributes.

The Can Class

A Can has the following attributes: its diameter, height, and weight (positive integers); its contents (a string); and the name of the person to whom the can is addressed (another string). A can is uniquely identified by all of its attributes.
Exceptions
At a minimum, your project must detect the following invalid conditions and throw an appropriate exception. You must create your own exception classes to deal with these conditions.
  1. An attempt to load a box/can/sack into a truck that is full
  2. An attempt to deliver a box/can/sack from a truck that is empty
  3. An attempt to deliver a non-existent box/can/sack
Exceptions should also be thrown for any other exceptional conditions which may occur in your particular implementation.
The Command File
The command file has the following format. Blank lines may appear anywhere in the file and should be ignored. Any non-blank line may be assumed to be properly formatted and all data may be assumed to be valid. All dimensions (height, width, etc) are in inches. All weights are given in pounds. A small sample command file is available.

The attributes of the BOX for the LOAD and DELIVER commands are separated by white space and occur in the following order:
contents (a string with no spaces), length, width, height, weight, and the name of the person to whom the box should be delivered (a string which may contain spaces)

The attributes of the SACK for the LOAD and DELIVER commands are separated by white space and occur in the following order:
contents (a string with no spaces), material (a string with no spaces), weight, and the name of person to whom the box should be delivered (a string which may contain spaces).

The attributes of the CAN for the LOAD and DELIVER commands are separated by white space and occur in the following order:
contents (a string with no spaces), diameter, height, weight, and the name of the person to whom the box should be delivered (a string which may contain spaces).


Sample Output
Your program must produce the following outputs displayed to the screen and output to the specified file on the command line.
  1. Each time a command (other than COMMENT) is read from the command file the command and its parameters must be displayed.
  2. Each time the PRINT command is encountered, the current location, current mileage and list of current contents of all trucks must be printed. All attributes of each box, can, and sack must be displayed.
This sample output was NOT produced by processing any command file. It is intended solely to provide an example of an acceptable output format. Any similar format is allowed as long as all required data is provided.
linux1[5]% proj5.Project5 40 commands.dat
Processing File: commands.dat

Cmd: PRINT
     BOX TRUCK
     The truck's current locations is: Warehouse
     The truck has driven 0 miles so far
     The truck is empty

     SACK TRUCK
     The truck's current locations is: Warehouse
     The truck has driven 0 miles so far
     The truck is empty

     CAN TRUCK
     The truck's current locations is: Warehouse
     The truck has driven 0 miles so far
     The truck is empty

Cmd: LOAD BOX oranges 2 3 4 9 Bob Smith
Cmd: LOAD BOX Toys 2 4 5 12 Santa
Cmd: LOAD CAN Soup 4 3 1 Bob's Big Boy Restaurant
Cmd: LOAD SACK corn paper 50 Tommy Jones
Cmd: DRIVE BOX Catonsville 20
Cmd: PRINT
     BOX TRUCK
     The truck's current locations is: Catonsville
     The truck has driven 20 miles so far
     The truck's contents
     -------
	 L x W x H: 2 x 3 x 4
	 Contents: oranges
	 Weight: 9 lbs
	 Addressed to: Bob Smith
     --------
	 L x W x H: 2 x 4 x 5
	 Contents: Toys
	 Weight: 12 lbs
	 Addressed to: Santa

     SACK TRUCK
     The truck's current locations is: Warehouse
     The truck has driven 0 miles so far
     The truck's contents
	 ------
	 Material: paper
	 Contents: corn
	 Weight: 50 lbs
	 Addressed to: Tommy Jones

	 CAN TRUCK
     The truck's current locations is: Warehouse
     The truck has driven 0 miles so far
     The truck's contents
	 ------
     D x H: 4 x 3
	 Contents: Soup
	 Weight: 1 lbs
	 Addressed to: Bob's Big Boy Restaurant
    

Requirements, Hints, and Tips
  1. Mr. Frey's public directory for this project is
    /afs/umbc.edu/users/f/r/frey/pub/CMSC202/Proj5
  2. The Truck, Box, Can, and Sack classes must be defined in a Java package named "trucks".
  3. Other classes you may create (e.g. exception classes) should also be part of the "trucks" package.
  4. The Project5 class that contains main must be defined in a Java package named "project5"
  5. Keep your classes simple and self-contained. Do not write unnecessary methods. Make sure each class is doing its own work.
  6. Make appropriate use of helper methods, especially for main.
  7. Don't use arrays
  8. If your Truck requires that the Box, Can, and Sack support specific methods other than those they inherit from Object, you must define and implement an appropriate interface for those methods.

Project Design Assignment
Copy the file p5design.txt from Mr. Frey's public directory and edit it to answer the questions therein. Please note the due date for the design is different from the project due date.
Extra Credit
A quick look at the Sack, Box, and Can classes reveals that all these classes share some common attributes. It is therefore reasonable that these should be part of a class hierarchy, all derived from some base class (let's call it "Package") that contains these common attributes. This base class would also include any methods common to Sack, Box, and Can. With this hierarchy in place, your project can now store Sacks, Boxes, and Cans in the same Truck.


For 10 points of extra credit

  1. Define the class hierarchy of packages described above
  2. Implement the Sack, Box, and Can as derived classes of Package
  3. Instantiate just one Truck for loading, delivering, and moving all kinds of Packages. (Yes, the Truck must still be implemented using generics).
  4. In the command file, BOX|CAN|SACK in the LOAD and DELIVER commands will now specify what kind of package to LOAD onto/DELIVER from the one and only Truck, rather than which truck to LOAD onto/DELIVER from.
  5. In the command file, all DRIVE commands apply to the one and only truck. The second parameter of the DRIVE command (BOX|CAN|SACK) should be ignored.
  6. When PRINTing the truck contents, print each package's type in addition to its attributes.
  7. Submit a README file with your project telling the grader that you are seeking extra credit.


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.
Project Grading
The grade for this project will be broken down as follows. A more detailed breakdown will be provided in the grade form you receive with your project grade. This list should not be considered comprehensive, but rather a suggested list of things you should consider before turning in your project.

10% - Design Assignment

80% - Correctness

  1. Have you verified the command line and its parameters?
  2. Does your output meet all output requirements? Is all output produced by the appropriate class' method?
  3. Do all methods have the proper PreConditions? If so, are all PreConditions handled?
  4. Are you throwing exceptions wherever required?
  5. Are all exceptions being caught and handled properly? I.e. being thrown by the appropriate methods, caught by the caller and dealt with appropriately?
  6. Are your classes implemented using appropriate OOP principles -- encapsulation and abstraction?
  7. Does your Truck load/unload/print duplicate items correctly?

10% - Coding Standards

Your code adheres to the CMSC 202 coding standards as discussed and reviewed in class.
Project Submission
Remember that the project due date/time are firm. Submit all .java files you created for this project. No files are provided for you for this project.

Submit as follows:

           submit cs202 Proj5 <list of files>

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.