Answered step by step
Verified Expert Solution
Link Copied!

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 2024
Assignment 1
(Last modified on January 10,2024)
Deadline: February 2,2024,11:30 pm
Learning objectives
Edit, compile and run Java programs
Utilize arrays to store information
Apply basic object-oriented programming concepts
Understand the university policies for academic integrity
Introduction
This year, we are going to implement, through a succession of assignments, a simple parking-lot simulator and
optimizer. For Assignment 1, 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 1.
S, S, S, S, N
R, R, L, L, E
R, R, L, L, E
S, S, S, S, N
###
0,1, S, ABC
1,2, L, ABD
3,3, S, ABX
Figure 1: Example input file
You will parse the input data and build the conceptual memory representation shown in Figure 2. More precisely, we get: (1) an instance variable, lotDesign, instantiated with a with a two-dimensional CarType array (of
size 4\times 5) and (2) an instance variable, occupancy, instantiated with a two-dimensional 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 parking-lot design when a spot is usuitable
for parking a car (e.g., when pillars or building facilities are blocking the spot).
1
8
>>>>>>>>>>>><
>>>>>>>>>>>>:
:>>>>>>>>>>>>>>>>>>>>>>>
<>>>>>>>>>>>>>>>>>>>>>>>
8
5 parking spots per row
4 rows
CarType[4][5]
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[0][0] as an example. For the input file shown in Figure 1, lotDesign[0][0] 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).
*
8
>>>>>>>>>>>><
>>>>>>>>>>>>:
:>>>>>>>>>>>>>>>>>>>>>>>
<>>>>>>>>>>>>>>>>>>>>>>>
8
5 parking spots per row
4 rows
Car[4][5]
occupancy null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
null
Car
instance 1
Car
instance 2
Car
instance 3
Figure 2: Results of processing the example occupancy input of Figure 1
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 18 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): 18
Number of cars currently parked in the lot: 3
==== Lot Design ====
S, S, S, S, N
R, R, L, L, E
R, R, L, L, E
S, S, S, S, N
==== Parking Occupancy ====
(0,0): Unoccupied
(0,1): S(ABC)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions