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.
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:
cp -R /csclass/mohammad/public-html/classes/csc241/parkingLot .
-- don't forget the space followed by dot
chmod og+rx parkingLot
-- make the directory public.
cd parkingLot
-- get into the parkingLot directory.
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
javac *.java
-- to compile parkingLot and test
programs.
more test1.java
java test1
more test2.java
java test2
-- when prompted for
a data file, enter test2.dat
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:
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.
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
As shown above
for enter, a comment section should be added to the
exit method in the parkingLot class with its pre/post conditions.
We like our parkingLots to keep track of their max value of carCount_. Do the following:
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