Sys 5110 Java Assign
Sys 5110 Java Assign
Instructions
Submit the assignment via Blackboard Learn and ensure that all Java files are identified with your
name and student number (in comments). In addition to developing a number of Java class files,
provide a design document in PDF form with the name ParkingLotDesign_xxxx.pdf, where xxxx is
replaced with your student number. The following are specific instructions for this assignment:
Question 1 should be answered in files Car.java and ParkingLot.java (templates have been
provided). UML diagrams should be pasted in the design document. The file TestQ1.java is
provided to test these two classes.
Question 2 should be answered in Java files ParkEvent.java and ParkEventList.java (templates have
been provided). UML diagrams should be pasted in the design document. The file TestQ2.java is
provided to test these two classes.
The file TestSimulation.java is provided to test all classes from both questions.
Submit only the Java files that you have completed, i.e. Car.java, ParkingLot.java, ParkEvent.java
and ParkEventList.java.
Zip the .pdf and .java, files in JavaAssign_xxxxxx.zip, where xxxxxx is your student number and
submit it via BlackBoard learn.
Be sure to start the assignment soon and not wait until the last weekend to start. Better to put many
small efforts over two weeks to complete the assignment than one single large effort two days
before the assignment is due.
Standards: 10 marks
Question 1: 45 marks
Question 2: 45 marks
1
In this assignment you shall be developing several classes to complete a software project where parking
of cars in different parking lots is simulated. The first question deals with creating the classes Car (to
represent cars) and ParkingLot (to represent parking lots). The second question deals with creating the
class ParkEvent which shall represent the event of a car either entering a lot or leaving a lot as well as
the class ParkEventList which contains a list (i.e. array) of ParkEvent objects. These latter classes
define a set of events that occur at specific points in times. Simulation of this system is called Discrete
Event Simulation. The following classes are provided to support your development:
TestQ1: For testing the classes from question 1.
TestQ2: For testing the classes from question 2.
TestSimulation: For testing all classes from both questions 1 and questions 2.
Time: This class is complete and is an alternate version of the Time class developed in Exercise
10.1
Car and ParkingLot: The classes provided are incomplete and need to be completed for
Question 1.
ParkEvent and ParkEventList: The classes provided are incomplete and need to be completed
for Question 2.
Question 1 (45 marks)
Implementation of a Car Class
Complete the implementation of a Java class Car that will store information for a car and provide
operations to work with the car. The following UML diagram provides the design of the class and
shows the private attributes and public methods included in the class.
Car
-enteringTime: Time
-plateNumber: String
+Car(plate:String)
+getEnteringTime(): Time
+getPlatNumber(): String
+setEnteringTime(): Time
+toString(): String
The methods are described in the template provided (Car.java) – see comments given for each method.
You may add private methods to the class to support your solution. Do update the UML diagram and
include in the Design Document.
2
Design and Implementation of a ParkingLot Class
Complete the design and implementation of Java class ParkingLot that will store information for a
parking lot, and provide operations to work with the lot. The following UML diagram shows the public
methods (and suggested private methods) included in the class. One attribute is shown, spots. The
attribute spots is a reference to an array of Car objects. Note that this array shall be of fixed size
(according to the capacity of the parking lot). The element of the array contains null when no Car
object is occupying the spot and a reference to a Car objet when it occupies the spot. Other attributes
are not shown; you are required to add additional attributes to be used.
ParkingLot
- spots: Car []
To be completed
+ParkingLot(name: String, rate: double, max: double, capacity: int)
+getDailyRevenue() : double
+getHourlyRate(): double
+getMaxCharge() : double
+getCapacity() : int
+resetDailyRevenue()
+resetLot(rate: double, max: double, capacity: int)
+carEnter(c: Car, t: Time)
+carLeave(c: Car, t: Time)
+print()
+toString()
-findCar(c: Car): int
-findSpot(): int
The methods are described in the Java template provided – see comments given for each method. You
may add private methods to the class to support your solution. Do update the UML diagram and
include in the Design Document.
Testing the Car and ParkingLot classes:
The class TestQ1 with a main() method (and other methods) is provided to test your ParkingLot
class and Car class. Appendix A provides the output from the execution of the main() method.
3
Question 2 (45 marks)
In this question, you will develop classes that allow the simulation of cars parking in parking lots. The
simulation of the parking lots is based on an approach called Discrete Event Simulation. A discrete
event is defined as a point in time at which a change is made to the model (in our specific case the
collection of ParkingLot and Car objects). Thus an event is defined as an object that contains a point
in time (i.e. a reference to a Time object), a reference to a ParkingLot object (where the change is to
be made), a reference to a Car object (which either enters or leaves the parking lot), and a reference to a
String object that contains the string “Enter” or “Leave” to indicate whether the car enters or leaves
the parking lot. An event in our model consists of a car either entering or leaving a parking lot.
To define a simulation over a day, a number of events (i.e. ParkingEvent objects) are defined and
stored in the ParkingEventList object. This latter object can then be used to “run” or “execute” the
simulation.
Implementing the ParkEvent Class (for creating an object that defines a parking event)
Complete the Java class ParkEvent that contains the information described above (which can be
different for each ParkEvent object). The following UML diagram provides a definition for the
ParkEvent class.
ParkEvent
+ENTER: String = “Enter”
+LEAVE: String = “Leave”
-theCar: Car
-theLot: ParkingLot
- eventTime: Time
- eventType: String
+ParkEvent(c: Car, p:ParkingLot, t:Time, evnt:String)
+getCar(): Car
+getParkingLot(): ParkingLot
+getTime(): Time
+isEnterEvent(): boolean
+isLeaveEvent(): boolean
+toString: String
The methods are described in the Java template provided (ParkEvent.java) – see comments given for
each method. You may add private methods to the class to support your solution. Do update the UML
diagram and include in the Design Document.
4
Design and Implementation of the ParkEventList Class (for creating and manipulating a list of
ParkEvent objects)
Complete the Java class ParkEventList that is designed to manage a list of ParkEvent objects; such
objects are used in the simulation of cars entering and leaving parking lots. The following UML
diagram provides a base definition for the ParkEventList class.
ParkEventList
- events: ParkEvent[]
+add(ev: ParkEvent)
+getEvent(ix: int): ParkEvent
+removeFirstEvent(): ParkEvent
+print()
The public methods are described in the Java template ParkEvent.java provided – see comments given
for each method. Note that no Constructor is provided or necessary (examine how the events attribute
is initialized). Do consider including private methods. In particular the add method can be simplified
if you defined separate private methods for adding an event at the start of the list, adding an event at the
end of the list and for inserting events within the list. Do update the UML diagram and include in the
Design Document.
Testing the ParkEvent and ParkEventList classes:
The class TestQ2 with a main() method (and other methods) is provided to test your ParkEvent
class and ParkEventList class. Appendix A provides sample output from the execution of the main()
method.
5
ITI1120 Class
The ITI1120 class was developed to simplify input from the keyboard. It provides more functionality
than the standard Java Scanner class. You may elect to used either class in your solution. For
documentation of this class, see the link in the Java Self Study page.
6
Appendix A
Q1 Output
***********************Enter Leave Tests*********************
---------------------------Enter Leave Test-----------------------
09:00 - Car CSI 356 entered Test Lot
>---------Test Lot----------<
+---------+---------+---------+---------+
| CSI 356 | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 0.00
>--------------------<
09:20 - Car CSI 356 left Test Lot and paid $ 1.75
>---------Test Lot----------<
+---------+---------+---------+---------+
| Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 1.75
>--------------------<
-------------------------------------------------------------------
---------------------------Enter Leave Test-----------------------
09:00 - Car CSI 356 entered Test Lot
>---------Test Lot----------<
+---------+---------+---------+---------+
| CSI 356 | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 1.75
>--------------------<
10:00 - Car CSI 356 left Test Lot and paid $ 3.50
>---------Test Lot----------<
+---------+---------+---------+---------+
| Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 5.25
>--------------------<
-------------------------------------------------------------------
---------------------------Enter Leave Test-----------------------
09:10 - Car CSI 356 entered Test Lot
>---------Test Lot----------<
+---------+---------+---------+---------+
| CSI 356 | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 5.25
>--------------------<
11:10 - Car CSI 356 left Test Lot and paid $ 7.00
>---------Test Lot----------<
+---------+---------+---------+---------+
| Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 12.25
>--------------------<
-------------------------------------------------------------------
---------------------------Enter Leave Test-----------------------
09:30 - Car CSI 356 entered Test Lot
>---------Test Lot----------<
+---------+---------+---------+---------+
| CSI 356 | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 12.25
>--------------------<
7
10:45 - Car CSI 356 left Test Lot and paid $ 5.25
>---------Test Lot----------<
+---------+---------+---------+---------+
| Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 17.50
>--------------------<
-------------------------------------------------------------------
---------------------------Enter Leave Test-----------------------
09:00 - Car CSI 356 entered Test Lot
>---------Test Lot----------<
+---------+---------+---------+---------+
| CSI 356 | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 17.50
>--------------------<
14:00 - Car CSI 356 left Test Lot and paid $ 8.00
>---------Test Lot----------<
+---------+---------+---------+---------+
| Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 25.50
>--------------------<
-------------------------------------------------------------------
8
11:04 - Car CSI 356 left Test Lot and paid $ 8.00
>---------Test Lot----------<
+---------+---------+---------+---------+
| Empty | PHY 391 | ELG 245 | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 15.00
>--------------------<
11:05 - Car CEG 109 entered Test Lot
>---------Test Lot----------<
+---------+---------+---------+---------+
| CEG 109 | PHY 391 | ELG 245 | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 15.00
>--------------------<
9
Q2 Output
****************Adding Events**********************
--------------------------------------------
--------------------------------------------
Added event: 10:30: Car is CSI 356, Lot is Lot 1, Enter event
--------------------------------------------
10:30: Car is CSI 356, Lot is Lot 1, Enter event
--------------------------------------------
Added event: 09:00: Car is ITI 193, Lot is Lot 2, Enter event
--------------------------------------------
09:00: Car is ITI 193, Lot is Lot 2, Enter event
10:30: Car is CSI 356, Lot is Lot 1, Enter event
--------------------------------------------
Added event: 14:00: Car is ELG 245, Lot is Lot 1, Enter event
--------------------------------------------
09:00: Car is ITI 193, Lot is Lot 2, Enter event
10:30: Car is CSI 356, Lot is Lot 1, Enter event
14:00: Car is ELG 245, Lot is Lot 1, Enter event
--------------------------------------------
Added event: 13:45: Car is CSI 356, Lot is Lot 1, Leave event
--------------------------------------------
09:00: Car is ITI 193, Lot is Lot 2, Enter event
10:30: Car is CSI 356, Lot is Lot 1, Enter event
13:45: Car is CSI 356, Lot is Lot 1, Leave event
14:00: Car is ELG 245, Lot is Lot 1, Enter event
--------------------------------------------
Added event: 10:15: Car is ITI 193, Lot is Lot 2, Leave event
--------------------------------------------
09:00: Car is ITI 193, Lot is Lot 2, Enter event
10:15: Car is ITI 193, Lot is Lot 2, Leave event
10:30: Car is CSI 356, Lot is Lot 1, Enter event
13:45: Car is CSI 356, Lot is Lot 1, Leave event
14:00: Car is ELG 245, Lot is Lot 1, Enter event
--------------------------------------------
****************Removing Events**********************
Removed event: 09:00: Car is ITI 193, Lot is Lot 2, Enter event
--------------------------------------------
10:15: Car is ITI 193, Lot is Lot 2, Leave event
10:30: Car is CSI 356, Lot is Lot 1, Enter event
13:45: Car is CSI 356, Lot is Lot 1, Leave event
14:00: Car is ELG 245, Lot is Lot 1, Enter event
--------------------------------------------
Removed event: 10:15: Car is ITI 193, Lot is Lot 2, Leave event
--------------------------------------------
10:30: Car is CSI 356, Lot is Lot 1, Enter event
13:45: Car is CSI 356, Lot is Lot 1, Leave event
14:00: Car is ELG 245, Lot is Lot 1, Enter event
--------------------------------------------
Removed event: 10:30: Car is CSI 356, Lot is Lot 1, Enter event
--------------------------------------------
13:45: Car is CSI 356, Lot is Lot 1, Leave event
14:00: Car is ELG 245, Lot is Lot 1, Enter event
--------------------------------------------
Removed event: 13:45: Car is CSI 356, Lot is Lot 1, Leave event
--------------------------------------------
14:00: Car is ELG 245, Lot is Lot 1, Enter event
--------------------------------------------
Removed event: 14:00: Car is ELG 245, Lot is Lot 1, Enter event
--------------------------------------------
--------------------------------------------
10
Simulation Sample Output
Configuration for Lot 1
Rate: $ 3.00
Max Charge: $ 12.00
Capacity: 4
----------------------------------------
Configuration for Lot 2
Rate: $ 3.50
Max Charge: $ 15.00
Capacity: 8
----------------------------------------
11
Enter your choice (1-4): 2
Please enter a value for seed: 1234
09:12 - Car PHY 391 entered Lot 1
>---------Lot 1----------<
+---------+---------+---------+---------+
| PHY 391 | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 0.00
>--------------------<
>---------Lot 2----------<
+---------+---------+---------+---------+---------+---------+---------+---------+
| Empty | Empty | Empty | Empty | Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+---------+---------+---------+---------+
Daily Revenue: $ 0.00
>--------------------<
--------------------------------------
Press any key to go to next event
12
12:50 - Car CEG 109 left Lot 2 and paid $ 12.25
>---------Lot 1----------<
+---------+---------+---------+---------+
| PHY 391 | CSV 346 | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 0.00
>--------------------<
>---------Lot 2----------<
+---------+---------+---------+---------+---------+---------+---------+---------+
| MAT 234 | Empty | Empty | Empty | Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+---------+---------+---------+---------+
Daily Revenue: $ 12.25
>--------------------<
--------------------------------------
Press any key to go to next event
13
15:30 - Car CSV 346 left Lot 1 and paid $ 10.50
>---------Lot 1----------<
+---------+---------+---------+---------+
| ITI 193 | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 22.50
>--------------------<
>---------Lot 2----------<
+---------+---------+---------+---------+---------+---------+---------+---------+
| MAT 234 | ELG 245 | Empty | Empty | Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+---------+---------+---------+---------+
Daily Revenue: $ 12.25
>--------------------<
--------------------------------------
Press any key to go to next event
14
18:03 - Car MCB 204 entered Lot 2
>---------Lot 1----------<
+---------+---------+---------+---------+
| Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 31.50
>--------------------<
>---------Lot 2----------<
+---------+---------+---------+---------+---------+---------+---------+---------+
| CSI 356 | ELG 245 | MCB 204 | Empty | Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+---------+---------+---------+---------+
Daily Revenue: $ 27.25
>--------------------<
--------------------------------------
Press any key to go to next event
15
19:21 - Car ELG 245 left Lot 2 and paid $ 15.00
>---------Lot 1----------<
+---------+---------+---------+---------+
| Empty | CHG 485 | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 34.50
>--------------------<
>---------Lot 2----------<
+---------+---------+---------+---------+---------+---------+---------+---------+
| CSI 356 | Empty | MCB 204 | Empty | Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+---------+---------+---------+---------+
Daily Revenue: $ 42.25
>--------------------<
--------------------------------------
Press any key to go to next event
16
Configuration for Lot 1
Rate: $ 3.00
Max Charge: $ 12.00
Capacity: 4
----------------------------------------
Configuration for Lot 2
Rate: $ 3.50
Max Charge: $ 15.00
Capacity: 8
----------------------------------------
17
17:39 - Car ITI 193 left Lot 1 and paid $ 9.00
18:03 - Car MCB 204 entered Lot 2
18:11 - Car MCG 243 entered Lot 1
18:50 - Car CHG 485 entered Lot 1
18:53 - Car MCG 243 left Lot 1 and paid $ 3.00
19:21 - Car ELG 245 left Lot 2 and paid $ 15.50
20:27 - Car CHG 485 left Lot 1 and paid $ 6.00
20:58 - Car MCB 204 left Lot 2 and paid $ 12.00
22:43 - Car CSI 356 left Lot 2 and paid $ 15.50
>---------Lot 1----------<
+---------+---------+---------+---------+
| Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+
Daily Revenue: $ 40.50
>--------------------<
>---------Lot 2----------<
+---------+---------+---------+---------+---------+---------+
| Empty | Empty | Empty | Empty | Empty | Empty |
+---------+---------+---------+---------+---------+---------+
Daily Revenue: $ 72.50
>--------------------<
Configuration for Lot 1
Rate: $ 3.00
Max Charge: $ 12.00
Capacity: 4
----------------------------------------
Configuration for Lot 2
Rate: $ 4.00
Max Charge: $ 15.50
Capacity: 6
----------------------------------------
18