Comp1405 A5 F2015
Comp1405 A5 F2015
a constructor that accepts two int parameters: one represents hours, and the other represents
minutes. These values should be stored into the instance variables. Note that you MUST
examine the minutes parameter ... if it is greater than 59, then you must transfer the multiples of
60 over to the hours portion of the Time object. (e.g., new Time(10,93) results in 11 hours and 33
minutes). Assume parameters are both >= 0.
another constructor that accepts a double parameter (assumed to be >= 0) which represents the
time and is used to initialize the instance variables. (e.g., a parameter value of 9.5 may either
represent the time 9:30am or a 9 hours and 30 minutes time range, while a parameter value of
20.75 may either represent a time of 8:45pm or a time range of 20 hours and 45 minutes.
a static (i.e., class) method difference(Time t1, Time t2), which returns a Time object that is the
difference between two Time objects (i.e., t2 t1). Note that negative times are allowed as well
as times with more than 24 hours are allowed.
Note that the test cases shown in blue are a little trickier. If you get stuck on these, finish the rest of the
assignment and then come back to them.
a constructor that takes two parameters to represent the cars license plate
number as well as a boolean indicating whether or not the car has a permit.
a constructor that takes no parameters, yet initializes ALL the attributes (i.e., instance variables) to
reasonable default values
a constructor that takes a lot number as well as a capacity as parameters and sets those
appropriately while setting all other attributes to reasonable default values.
a toString() method that returns a string representation of a parking lot that looks like this:
"Parking Lot #1 - rate = $3.25, capacity 4, current
cars 3"
Note that the values in red will obviously vary according to the lot's state.
Test your class with this program:
public class ParkingLotTestProgram {
public static void main(String args[]) {
ParkingLot p0 = new ParkingLot();
ParkingLot p1 = new ParkingLot(1, 4);
ParkingLot p2 = new ParkingLot(2, 6);
System.out.println(p0);
System.out.println(p1);
System.out.println(p2);
p1.hourlyRate = 5.5;
p1.maxCharge = 20.0;
p2.hourlyRate = 3.0;
p2.maxCharge = 12.0;
System.out.println(p1);
System.out.println(p2);
System.out.println(p1.maxCharge);
System.out.println(p2.maxCharge);
}
}
The result should be as follows (where ??? depends on your choice of default values):
Parking
Parking
Parking
Parking
Parking
20.0
12.0
Lot
Lot
Lot
Lot
Lot
#0
#1
#2
#1
#2
rate
rate
rate
rate
rate
=
=
=
=
=
$???,
$???,
$???,
$5.5,
$3.0,
capacity
capacity
capacity
capacity
capacity
ABC
ABC
ABD
ADE
AFR
AGD
AAA
AAA
AAA
ABB
XYZ
123
124
314
901
304
888
111
111
111
001
678
ADE
ABC
AGD
ABC
ABB
XYZ
ABB
AFR
AAA
ABD
ABB
901
124
888
123
001
678
001
304
111
314
001
Below is a test program that should produce the output log shown above. You will be getting this code
to work (in part 5) by completing the missing methods shown in red. For now, just make sure that you
understand why the test code produces the output shown above.
public class ParkingSimulationProgram {
public static void carEnters(ParkingLot p, Car c, Time t) {
// ... code is missing ...
}
public static void carLeaves(ParkingLot p, Car c, Time t) {
// ... code is missing ...
}
public static void main(String
Car car1 = new Car("ABC
car3 = new Car("ABD
car5 = new Car("AFR
car7 = new Car("AAA
car9 = new Car("XYZ
args[]) {
123"), car2 =
314"), car4 =
304"), car6 =
111"), car8 =
678", true);
new
new
new
new
Car("ABC
Car("ADE
Car("AGD
Car("ABB
124"),
901"),
888"),
001"),
System.out.println(p1);
System.out.println(p2 + "\n");
carEnters(p1,
carEnters(p1,
carEnters(p2,
carEnters(p2,
carEnters(p1,
carEnters(p1,
carEnters(p1,
carEnters(p2,
carEnters(p2,
carEnters(p2,
car1,
car2,
car3,
car4,
car5,
car6,
car7,
car7,
car8,
car9,
new
new
new
new
new
new
new
new
new
new
Time(7,
Time(7,
Time(8,
Time(8,
Time(8,
Time(8,
Time(8,
Time(8,
Time(8,
Time(8,
15));
25));
0));
10));
15));
20));
30));
32));
50));
55));
System.out.println("\n" + p1);
System.out.println(p2 + "\n");
carLeaves(p2,
carLeaves(p1,
carLeaves(p1,
carLeaves(p1,
carLeaves(p2,
carLeaves(p2,
carEnters(p1,
carLeaves(p1,
carLeaves(p2,
carLeaves(p2,
carLeaves(p1,
car4,
car2,
car6,
car1,
car8,
car9,
car8,
car5,
car7,
car3,
car8,
new
new
new
new
new
new
new
new
new
new
new
Time(9, 0));
Time(9, 05));
Time(10, 0));
Time(10, 30));
Time(13, 0));
Time(15, 15));
Time(17, 10));
Time(17, 50));
Time(18, 0));
Time(18, 15));
Time(20, 55));
System.out.println("\n" + p1);
System.out.println(p2 + "\n");
System.out.println("Total revenue of Lot 1 is $" + p1.revenue + ".");
System.out.println("Total revenue of Lot 2 is $" + p2.revenue + "."); ;
}
}
Make sure that your code is robust by handling some potential "impossible" or "weird" cases like the
ones shown below. You will need to add some code to the end of the ParkingSimulationProgram
to simulate these situations/cases. DO NOT MODIFY the current 9 cars or parking lots. Instead,
add these two lines to the end of the ParkingSimulationProgram:
System.out.println("===============================================================");
System.out.println("===============================================================");
And then add your own code to create some new cars and parking lots to test your special cases.
So, to be clear, you will hand in your ParkingSimulationProgram so that it contains the exact same
code as before, with additional code (or your making) appended to the end. Therefore, when the TA
runs your code, he/she should see the original output from part 4 followed by the lines produced from
the above println() statements, followed by the output for your special cases. For each case, please
add a single System.out.println() statement indicating what you are testing. For example, you may
do this:
System.out.println("Testing car trying to leave lot before it has entered ...");
// ... your code
System.out.println("Testing car entering and leaving lot at exact same time ...");
// ... your code
// etc..
NOTE: Submit a single zip file containing all of your .java file as well as all test programs. Submit your assignment using
CULearn. Note that if your internet connection at home is down or does not work, we will not accept this as a reason for
handing in an assignment late ... so make sure to submit the assignment WELL BEFORE it is due !
Please NOTE that you WILL lose marks on this assignment if any of your files are missing. You
will also lose marks if your pseudocode is not written neatly with proper indentation. See
examples in the notes for proper style.