CS 157 Spring 2003                Assignment 12 – Building a class, and using it                                                           100 points

 

Assigned: 04/16/2003

Due: 04/25/2003 (at the start of class – as will be the normal case)  Two labs devoted to this.

 

Pre-Lab (Do Before Lab):  Bring an empty (or nearly empty) disk. Plan out your instance variables and methods you will need for your Truck class. Plan a sequence of statements needed for the main class (TestTruck?).  This is another step up in complexity. Plan ahead!!

 

Main Assignment:

UPS has decided that they’d like you to help out with running their business.  For this assignment, we are making a simplifying assumption that all packages are alike (this will help a lot).  You will write a truck class that will allow keeping track of the state for a given truck – including an ID,  a capacity (number of boxes it can hold), current contents (number of boxes),  its location (a string), and a tally of how many boxes the truck has successfully delivered.   The truck class should provide behavior allowing – (besides normal constructors, inspectors, and mutators)  determining if the truck is full, picking up a given number of boxes (either from the current location or from another location), delivering a given number of boxes (either from the current location or from another location), and driving to another location.  It should also provide a toString method to enable quickly seeing the current state of the truck (this will take a little discussion in class).

You will also provide another class with a main method that will use the Truck class in order to dispatch a truck (for simplification we are sticking to only having one truck for now). This main should give the user the option of doing the above behaviors or quitting.  The results of the behaviors should be checked so that the user can be informed of any failures.  Once the user quits, some final info should be displayed.

 I would like your interaction with the user to be via dialog boxes, using static methods from RedmondMsgIn157 and RedmondMsgOut See the sample interaction below for a textual replay of what happened in one example.  

 

·         In using the readValidInt etc methods in RedmondMsgIn157, you automatically get validation.  If you use Keyboard methods, you must do validation on user inputs.

·         The RedmondMsgIn157, and RedmondMsgOut classes can still be obtained from my WWW page under assignments.

·         Put your name, e-mail address, and date in comments near the top (e.g.  /* Your Name */) in each file. 

·         Also, comment any significant code to document it (each method, each loop, each if, and each significant calculation should have a comment). 

·         Indent code following standard conventions (indent to show that something is “inside” or “part of” the preceding code (e.g. inside if’s or loops, or statements continued on a new line). 

 

Compile the program and remove any errors. Ensure that the program runs correctly. It should run on any set of inputs (test it on more than the example below!!, I will!!).

                To avoid needless long waits, I recommend doing this on the c: drive, then upon completion, copying it to the a: drive, testing it there, creating an extra backup for yourself, then deleting it from the c: drive.

 

Hand in:

 

Sample Interaction:

Choice: 1) Pickup here; 2) Dropoff here; 3) Travel Somewhere; 4) Pickup somewhere; 5) Dropoff somewhere; 6) Quit

1

How Many?

10

Truck: Truck: 1 Loc: Philadelphia Contains: 10 of 20 possible Boxes Delivered: 0

Choice: 1) Pickup here; 2) Dropoff here; 3) Travel Somewhere; 4) Pickup somewhere; 5) Dropoff somewhere; 6) Quit

3

Where to go to?

Bensalem

Truck: Truck: 1 Loc: Bensalem Contains: 10 of 20 possible Boxes Delivered: 0

Choice: 1) Pickup here; 2) Dropoff here; 3) Travel Somewhere; 4) Pickup somewhere; 5) Dropoff somewhere; 6) Quit

2

How Many?

12

How Many? (between 1 and 10)

5

Truck: Truck: 1 Loc: Bensalem Contains: 5 of 20 possible Boxes Delivered: 5

Choice: 1) Pickup here; 2) Dropoff here; 3) Travel Somewhere; 4) Pickup somewhere; 5) Dropoff somewhere; 6) Quit

4

Where to Pickup from?

West Chester

How Many?

10

Truck: Truck: 1 Loc: West Chester Contains: 15 of 20 possible Boxes Delivered: 5

Choice: 1) Pickup here; 2) Dropoff here; 3) Travel Somewhere; 4) Pickup somewhere; 5) Dropoff somewhere; 6) Quit

5

Where to Dropoff at?

Chester

How Many?

3

Truck: Truck: 1 Loc: Chester Contains: 12 of 20 possible Boxes Delivered: 8

Choice: 1) Pickup here; 2) Dropoff here; 3) Travel Somewhere; 4) Pickup somewhere; 5) Dropoff somewhere; 6) Quit

4

Where to Pickup from?

Cherry Hill

How Many?

10

Sorry Pickup failed

Truck: Truck: 1 Loc: Cherry Hill Contains: 12 of 20 possible Boxes Delivered: 8

Choice: 1) Pickup here; 2) Dropoff here; 3) Travel Somewhere; 4) Pickup somewhere; 5) Dropoff somewhere; 6) Quit

4

Where to Pickup from?

Marlton

How Many?

2

Truck: Truck: 1 Loc: Marlton Contains: 14 of 20 possible Boxes Delivered: 8

Choice: 1) Pickup here; 2) Dropoff here; 3) Travel Somewhere; 4) Pickup somewhere; 5) Dropoff somewhere; 6) Quit

5

Where to Dropoff at?

Philadelphia

How Many?

18

How Many? (between 1 and 14)

7

Truck: Truck: 1 Loc: Philadelphia Contains: 7 of 20 possible Boxes Delivered: 15

Choice: 1) Pickup here; 2) Dropoff here; 3) Travel Somewhere; 4) Pickup somewhere; 5) Dropoff somewhere; 6) Quit

6

Exiting

Final Results

current truck: Truck: 1 Loc: Philadelphia Contains: 7 of 20 possible Boxes Delivered: 15