CMSC 202 Project 5

The Delivery Truck

Assigned
Wednesday, December 2, 2009
Program Due
11:00pm, Monday, December 14, 2009
Weight
10%
Updates
When comparing string attributes of packages (e.g. the address), assume that comparisons are string insensitive (e.g. "ABC Company" is the same as "abc Company").

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 one delivery truck. The truck will load packages (boxes, cans, and sacks), drive from one destination to another, deliver packages, and print an inventory of the truck's contents. Commands read from a command file direct your truck. Output from your project will be displayed on the screen and also written to a text file.

This project will retrieve some input from the command line. The command line will have three arguments:

  1. The maximum number of packages (boxes, cans, and sacks) the truck can carry
  2. The name of the input command file
  3. The name of the output file


Class Definitions

For this project, you will implement a generic Truck class and a class named Project5, whose only purpose is to contain the code for main() and main()'s helper methods. You will also implement a hierarchy of package classes, with Package as the base class and Box, Can, and Sack as its derived classes.

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 (maximum number of packages) as read from the command line
  2. Its current location
  3. The current 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 Package Hierarchy

Your program must implement a hierarchy of packages, with the Package class as the base class and Box, Can, and Sack classes as its derived classes. Be sure to make proper use of inheritance in your hierarchy.

Boxes

A box has the following attributes: length, width, height (all in inches), weight (in pounds), its contents (a string), and the name of the person or place of business to which it is addressed. A box is uniquely identified by all of its attributes.

Cans

A can has the following attributes: its diameter and height (both in inches), weight (in pounds), its contents (a string), and the name of the person or place of business to which it is addressed. A can is uniquely identified by all of its attributes.

Sacks

A sack has the following attributes: its contents (a string), the material from which it is made (a string), weight (in pounds), and the name of the person or place of business to which it is addressed. A sack is uniquely identified by all of its attributes.


Exceptions

At a minimum, your project must detect the following invalid conditions and throw appropriate exceptions. You must create your own exception classes to deal with these conditions.

  1. An attempt to load a box/can/sack into the truck when it is full
  2. An attempt to deliver a box/can/sack from the truck when it is empty
  3. An attempt to deliver a non-existent box/can/sack
Exceptions should also be thrown for any other exceptional conditions that may occur in your particular implementation.
The Command File

A 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 or place of business to which the box should be delivered (a string that 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 or place of business to which the box should be delivered (a string that 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 or place of business to which the box should be delivered (a string that may contain spaces).


Sample Output

Your program must produce the following outputs displayed to the screen and also written to the text file specified 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 the current truck contents must be printed. All attributes of each box, can, and sack must be displayed.
This sample output was NOT produced by processing the sample command file given above. 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. Additionally, the required data does not have to be displayed in the exact same order as that shown in the sample output, as long as it's all there and is easy to read.
    

Requirements, Hints, and Tips
  1. (Reqirement) All classes in this project should be in a package named proj5.
  2. (Requirement) The Truck class should have no idea of the specific types of packages (boxes, cans, or sacks) that it contains.
  3. (Requirement) All console and file input/output should be handled by the Project5 class only.
  4. (Requirement) Keep your classes simple and self-contained. Do not write unnecessary methods. Make sure each class is doing its own work.
  5. (Requirement) Make appropriate use of helper methods, especially for main.
  6. (Requirement) Don't use arrays.

Project Policy

This project is considered an CLOSED project. Please review the CLOSED project policy on the course website.


Grading

See the course website for a description of how your project will be graded.


Project Submission
  1. Since no files are provided for you, be sure to submit all .java files necessary to compile and run your project.
  2. Use submitls to verify that they are in the remote directory.
The order in which the files are listed doesn't matter. However, you must make sure that all files necessary to compile and run your project are submitted. 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!