CIS 636 Spring 2005       Assignment 3 – Object Oriented Programming in Java – Using an Existing Class     100 points

Assigned: 02/03/2005

Due: 02/10/2005 at the start of class 

 

You may work individually or in pairs for this assignment. But all work must be the work of the person/people whose name is on the code! If working in pairs, the individual contributions should be relatively equal. One possibility is to work together tonight, then finish separately (to avoid communication difficulties).

 

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) and a lot of other simplifying assumptions!.  You have been provided a simplified 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 provides 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 also provides a toString method to enable quickly seeing the current state of the truck (Use this!). 

You will 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 RedmondMsgInBasic and RedmondMsgOut. See the sample interaction below for a textual replay of what happened in one example.  

Hand in:

 

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

 

Miscellaneous:

·        The UPSTruckSimple class is provided on the assignment page of my WWW site, along with documentation. It is written with a package statement that assumes that it is in a package of the same name.  If you use a different package, change the package statement. You should be able to use the same IO package you created for assignment 2. If you need to obtain it again, you can get any of my IO code you need from the assignment or review page of my WWW site.  It is written with a package statement that assumes that it is in a package of named IO.  If you use a different package, change the package statement.

·        You shouldn’t have to change anything in the UPSTruckSimple class (unless you are adding extra capability to your program). If you think you need to, ask me.

·        You shouldn’t have to change anything in RedmondMsgInBasic and RedmondMsgOut. The recommended methods make some simplifying assumptions, since we haven’t covered exception handling yet. This means that some exceptions will result if the user tries hard enough. Until we cover exceptions, we won’t catch invalid values that are the wrong type (e.g. letters where numbers are needed)).  No biggie at this point.

·        In using the readValidInt etc methods in RedmondMsgInBasic, you automatically get validation.  The number of packages to drop off or pick up should always be positive, and should never be allowed to exceed the capacity of the truck.

·        MAKE SURE YOUR PROGRAM WORKS! (i.e. more than just removing compile errors). Try more than the below example; convince yourself that it works.  Be a skeptic. 

·        Put YOUR NAME, and e-mail address and date in comments at the beginning of the program.

·        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).  The IDE should handle this if you hit ENTER and move on to the next line (If you make changes, you may need to TAB to make things right).

·        Name your variables meaningfully, to describe their use in the program.


Textual Version of 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