Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Winter 2 0 2 4 Assignment 1 ( Last modified on January 1 0 , 2 0 2 4 ) Deadline: February 2 , 2
Winter
Assignment
Last modified on January
Deadline: February : pm
Learning objectives
Edit, compile and run Java programs
Utilize arrays to store information
Apply basic objectoriented programming concepts
Understand the university policies for academic integrity
Introduction
This year, we are going to implement, through a succession of assignments, a simple parkinglot simulator and
optimizer. For Assignment we have modest goals though: we would like to read from a file the design and the
occupancy information of a parking lot, and perform some basic operations, for example, parking a car at a certain
spot in the lot. What you need to do in this assignment is illustrated with an example. Suppose we have a file
named parking.inf with the content shown in Figure
S S S S N
R R L L E
R R L L E
S S S S N
###
S ABC
L ABD
S ABX
Figure : Example input file
You will parse the input data and build the conceptual memory representation shown in Figure More precisely, we get: an instance variable, lotDesign, instantiated with a with a twodimensional CarType array of
size times and an instance variable, occupancy, instantiated with a twodimensional Car array of the same size
as lotDesign These arrays will be populated with the data in the input file. The lotDesign variable represents
the design of the parking lot and the occupancy variable keeps track of the cars that are parked in the lot.
CarType is an enumeration class defined as follows:
public enum CarType
ELECTRIC, SMALL, REGULAR, LARGE, NA;
In the input file, the letter E means ELECTRIC, S means SMALL, R means REGULAR, L means LARGE
andN means Not Applicable NA The special NA value is used in the parkinglot design when a spot is usuitable
for parking a car eg when pillars or building facilities are blocking the spot
:
:
parking spots per row
rows
CarType
lotDesign S
R
R
S
S
R
R
S
S
L
L
S
S
L
L
S
N
E
E
N
Let us take lotDesign as an example. For the input file shown in Figure lotDesign will refer to CarType.SMALL
once the file has been processed. Note that S R L E and N in the above representation are not characters or strings.
Rather, these are references to the literals in the CarType enumeration class respectively: SMALL, REGULAR, LARGE,
ELECTRIC and NA
:
:
parking spots per row
rows
Car
occupancy null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
Car
instance
Car
instance
Car
instance
Figure : Results of processing the example occupancy input of Figure
There are a number of methods in Car and ParkingLot that you need to implement. When necessary, guidance
is provided in the template code in the form of comments. The locations where you need to write code have been
clearly indicated with an inline comment that reads as follows:
WRITE YOUR CODE HERE!
The toString methods for both Car and ParkingLot have been provided to you in full. Similarly, the
main method in ParkingLot has been provided. You do not need to change these methods, but you are
encouraged to study them carefully.
Once the remaining methods in Car and ParkingLot have been implemented, running ParkingLot.main
will produce the following output. Note that our example parking lot has only parkable spots, since two spots
in the lot design are marked as N In our example, there is a total of three cars parked in the lot.
$ java ParkingLot
Please enter the name of the file to process: parking.inf
Total number of parkable spots capacity:
Number of cars currently parked in the lot:
Lot Design
S S S S N
R R L L E
R R L L E
S S S S N
Parking Occupancy
: Unoccupied
: SABC
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started