Design a Parking Lot
Let's make an object-oriented design for a multi-floor parking lot.
A parking lot or car park is a dedicated cleared area that is intended for
parking vehicles. In most countries where cars are a major mode of
transportation, parking lots are a feature of every city and suburban area.
Shopping malls, sports stadiums, megachurches, and similar venues often
feature parking lots of large area.
Use case diagram
Here are the main Actors in our system:
Admin: Mainly responsible for adding and modifying parking floors,
parking slots, entrance and exit panels, adding/removing parking
attendants, etc.
Customer: All customers can get a parking ticket and pay for it.
Parking attendant: Parking attendants can do all the activities on the
customer’s behalf, and can take cash for ticket payment.
System: To show messages on to different info panels, as well as
assigning and removing a vehicle from a parking slot.
Here are the top use cases for Parking Lot:
Add/Remove/Edit parking floor: To add, remove or modify a parking
floor from the system. Each floor can have its own display board to show
free parking slots.
Add/Remove/Edit parking slot: To add, remove or modify a parking
slot to a parking floor.
Add/Remove a parking attendant: To add or remove a parking
attendant from the system.
Take ticket: Customers will take a new parking ticket when entering the
parking lot.
Scan ticket: To scan a ticket to see how much it would charge.
Credit card payment: To pay the ticket fee through credit card.
Cash payment: To pay the parking ticket through cash.
Add/Modify parking rate: Admin can add or modify the hourly parking
rate.
Use-case diagram
Class diagram
Here are the main classes of our Parking Lot System:
ParkingLot: The central part of the organization for which this software
has been designed. It has attributes like ‘Name’ to distinguish it from
any other parking lots and ‘Address’ to define its location.
ParkingFloor: The parking lot will have many parking floors.
ParkingSlot: Each parking floor has many parking slots. Our system
will support different parking slots 1) Handicapped, 2) Compact, 3)
Large, 4) Motorbike, and 5) Electric.
Account: We will have two types of accounts in the system, one will be
an Admin, and the other will be of a parking attendant.
Parking ticket: This class will be encapsulating a parking ticket.
Customers will take a ticket when they enter the parking lot.
Vehicle: Vehicles will be parked in the parking slots. Our system will
support different types of vehicles 1) Car, 2) Truck, 3) Electric, 4) Van
and 5) Motorbike.
EntrancePanel and ExitPanel: EntrancePanel will be printing tickets,
and ExitPanel will facilitate paying the fee against a parking ticket.
Payment: Will be responsible for making a payment transaction. The
system will support credit card and cash transactions.
ParkingRate: This class will keep track of the hourly parking rates. For
every hour it will specify a dollar amount. For example, for a two hours
parking ticket, this class will tell how much would it cost for the first
hour and how much for the second hour.
ParkingDisplayBoard: Each parking floor will have a display board to
show available parking slots for each slot type. This class will be
responsible for displaying the latest state of free parking slots to the
customers.
ParkingAttendantPortal: This class will encapsulate all the operations
that an attendant can perform, like scanning a ticket and processing the
payments.
CustomerInfoPortal: This class will encapsulate the info portal that the
customers use to pay for the parking ticket. Once paid the info portal
update the ticket to keep track of the payment.
ElectricPanel: Customers use the electric panels to pay and charge their
electric vehicles.
Class diagram
Activity diagrams
Customer paying for parking ticket: Any customer can perform this activity.
Here are the set of steps:
Code
Following is the skeleton code for our parking lot system: