-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParkingLot
42 lines (34 loc) · 1 KB
/
ParkingLot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public class ParkingLot {
// private data field
private Level[] lvls;
// constant variable
private final int NUM_OF_LEVELS = 5;
// constructor
public ParkingLot(){
lvls = new Level[NUM_OF_LEVELS];
for (int count = 0; count < NUM_OF_LEVELS; count++){
lvls[count] = new Level(count, 30);
} // end of for loop
} // end of constructor
public boolean parkVeh(Vehicle veh){
for (int count = 0; count < lvls.length; count++){
if (lvls[count].parkVeh(veh)){
// return statement
return true;
}
} // end of for loop
// return statement
return false;
} // end of parkVeh method
// print out the result in string style
public String toString(){
// creating instance
StringBuilder sb = new StringBuilder();
// print out parking lot
for (int count = 0; count < NUM_OF_LEVELS; count++){
sb.append("Level " + count + ": " + lvls[count] + "\n");
} // end of for loop
// return statement
return sb.toString();
} // end of toString method
} // end of ParkingLot class