CS 280 Spring 2008

Assignment 5 – Writing(Most of) a Class

100 points

 

Assigned: 02/13/2008

Due: 02/20/2008 at the start of class

 

Pre-Lab (Do Before Lab):  Bring materials – a USB for a take home copy. Download and unzip the code that I’m providing. Look at Javadoc documentation to try to understand the methods that I’m asking you to provide.

 

Main Assignment:

Imagine that you are writing some parts of a Delivery Truck Simulation program (Truck World).  We are still a bit away from being able to do the full job, so pay attention to what I’m asking for.  I have provided a class that controls a GUI AND the beginnings of a class called DeliveryTruck. Your job is to complete the DeliveryTruck class so that the GUI class can run the simulation. You should NOT have to change the GUI class to make it run (I am asking for slight changes; see miscellaneous below). The provided classes will be in a zip file on Blackboard, along with Javadoc documentation for the classes.  Part of the Javadoc is included below; as a quick introduction, you should create methods:

1.      3 constructors besides the default constructor already provided – one that is just passed a truck id, one that is passed a truck id and a starting location, and one that is passed a truck id, starting location and number of boxes in the truck.

2.      Simple inspectors for all 5 instance variables (class data). Each should merely return the desired value.

3.      Simple mutators for truck id and current location. Each should set the appropriate instance variable to the passed value.

4.      Controlled mutators for numeric instance variables. Each numeric instance variable should have a method to:

a.      Reset it to zero

b.      Add a passed amount to it (no checking of passed value is required)

5.      In addition, there should be a subtractContains method that subtracts a passed amount from the number of boxes currently on the truck.

6.      There should be a dropoff method that given a passed number of boxes, subtracts that number of boxes from the contents of the truck and adds the same amount to the number of boxes delivered.

7.      A toString method that turns a DeliveryTruck into a reasonable String representation of the truck. See screen shot below showing the GUI’s use of my version of toString to display two trucks.

Hand in:

 

Miscellaneous:

·         Add  your name to mine in the jlabel at the top of  the GUI form.

o    MAKE SURE YOUR PROGRAM WORKS! (i.e. it must provide all of the requested capabilities AND provide them in the expected way – don’t change my code to make your code work!  Check that the desired parameters and return types are provided).

o    You MUST include some comments that explain your program in order to get full credit, including a javadoc comment for each method!!