CSC 241- Lab 2 (Due September 29, 2003)


Theme ...

You will make changes in the state and behavior of parkingLot and test your changes. You will also write the pre/post conditions for the exit method.


Copy the parkingLot Directory

You need to get into your public-html/classes/csc241 directory. You can issue a pwd at your unix prompt to see where you are at any time. The first command (the cp with the -R flag) copies a directory and any files and directories that are in it; the next pair put you in the the directory and let you view a listing of the files copied:

  1. cp -R /csclass/mohammad/public-html/classes/csc241/parkingLot . -- don't forget the space followed by dot
  2. chmod og+rx parkingLot -- make the directory public.
  3. cd parkingLot -- get into the parkingLot directory.
  4. ls -- This is the letter l followed by s; you should have the following list of files:
    parkingLot.java  test1.java       test2.dat        test2.java

Compile parkingLot and the test programs and run the programs

  1. javac *.java -- to compile parkingLot and test programs.
  2. Briefly study the code for each test program and run each.

Modify the concept of capacity

Currently, capacity is public static final which means there is only one constant capacity for all parkingLots and it is accessible in applications that use parkingLot. If we wish for each parkingLot to have a different capacity, we need to change capacity into a field like carCount_. We want to either set capacity to a default value of 100 or let its value be specified via a parameter at the time of construction.

The following are the things that you need to do:

Test Changes

Use test1 as an example and write a simple test program that ensure your changes worked correctly. Your test program should construct a t1 and a t2, but make t1 using the default constructor and t2 with the constructor that sets initial capacity. Use the capacity() method after constructing the two parkingLots and output their capacities.

I am not going to ask for this test program to be sent to me, but be aware that you will receive zero points for this portion of the lab, if there are any errors in implementing capacity as a field.


Write Pre/post conditions

Here are the pre/post conditions for method enter.
  public void enter () throws parkingLotOverFlowException {
  /**
      Precondtion: carCount_ < capacity_
      Postcondition: carCount_ == carCount_~+1
   **/

In the precondition we are specifying what we consider a valid state for our variables before we perform the task(s) needed for the method. (i.e. what are our assumptions about them, in order for the method to behave correctly). In the above precondition, carCount_ has to be less than capacity_; if its not, we can't bring in anymore cars. If this precondition is not met, we throw an exception. In the Postcondition, carCount_~ refers to the old value of carCount_, and it simply states that the new value must be equal to the old value plus 1 after this method is executed. This postcondition states in a formal way that carCount_ will be incremented by 1 after a call to eneter



Implement the concept of max

We like our parkingLots to keep track of their max value of carCount_. Do the following:


What to turn in

Email me parkingLot.java as an attachment. Changes to the concept of capacity, the pre/post condition for exit, and the implementation of the concept of max must be present in this file. Although, you are not expected to turn in your test programs, I am assuming you wrote them and tested this new version of parkingLot thoroughly. DO NOT SEND the .CLASS FILE