-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTesting2
110 lines (91 loc) · 3.38 KB
/
Testing2
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
public class Testing2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
// creating instance
ParkingLot pLot = new ParkingLot();
// variable declaration
String inp = "";
// scanner input
Scanner input = new Scanner (System.in);
// output
// print out an empty parking lot
System.out.println("The empty parking lot\n");
System.out.println(pLot.toString());
// input
// ask user to type in the vehicle that he wants to park
System.out.print("Please enter bus, car, or motorcycle a vehicle (enter 0 to exit): ");
inp = input.next();
// continue asking user for input until user enters zero
while(!inp.equals("0")){
if (inp.equals("Bus") || inp.equals("bus")){
// creating instance
Bus b = new Bus();
if(pLot.parkVeh(b)){
// vehicle parked
// success message
System.out.println("\nThe bus has been parked successfully.");
// print out parking lot
System.out.println(pLot.toString());
// ask user to enter other input
System.out.print("Please enter bus, car, or motorcycle to park a vehicle (enter 0 to exit): ");
inp = input.next();
} else {
// failure message
System.out.println("\nParking Failed: Bus spots are full");
// ask user to re-enter their inputs
System.out.print("Please enter car or motorcycle to park a vehicle (enter 0 to exit): ");
inp = input.next();
}
} else if(inp.equals("Car") || inp.equals("car")){
// creating instance
Car c = new Car();
if(pLot.parkVeh(c)){
// vehicle parked
// success message
System.out.println("\nThe car has been parked successfully.");
// print out parking lot
System.out.println(pLot.toString());
// ask user to enter other input
System.out.print("Please enter bus, car, or motorcycle to park a vehicle (enter 0 to exit): ");
inp = input.next();
} else {
// failure message
System.out.println("\nParking Failed: large spots are full");
// ask user to re-enter their inputs
System.out.print("Please enter bus or motorcycle to park a vehicle (enter 0 to exit): ");
inp = input.next();
}
} else if(inp.equals("Motorcycle") || inp.equals("motorcycle")){
// creating instance
Motorcycle m = new Motorcycle();
if(pLot.parkVeh(m)){
// vehicle parked
// success message
System.out.println("\nThe motorcycle has been parked successfully.");
// print out parking lot
System.out.println(pLot.toString());
// ask user to enter other input
System.out.print("Please enter bus, car, or motorcycle to park a vehicle (enter 0 to exit): ");
inp = input.next();
} else {
// failure message
System.out.println("\nParking Failed: Motorcycle spots are full");
// ask user to re-enter input
System.out.print("Please enter Bus or car to park a vehicle (enter 0 to exit): ");
inp = input.next();
}
} else {
// failure message
System.out.println("\nInvalid input.");
// ask user to re-enter input
System.out.print("\nPlease enter bus, car, or motorcycle to park a vehicle (enter 0 to exit): ");
inp = input.next();
}
// terminating program
if(inp.equals("0")){
System.out.print("\nProgram terminated");
break;
}
} // end of while loop
} // end of main method
} // end of Testing2 class