-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSE.java
More file actions
335 lines (262 loc) · 10.5 KB
/
SE.java
File metadata and controls
335 lines (262 loc) · 10.5 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class SE {
public class Bike extends Vehicle{
private boolean hasSideCar;
public Bike(String vehicleNum, LocalTime entryTime, boolean hasSideCar) {
super(vehicleNum, entryTime);
this.hasSideCar = hasSideCar;
}
public boolean isHasSideCar(){
return hasSideCar;
}
@Override
public String getVehicleType() {
return "Bike";
}
@Override
public double calculateFees(long durationInMinutes) {
double ratePerHour = 30;
if (durationInMinutes < 60 ){
durationInMinutes = 60;
}
return ((double)durationInMinutes/60) * ratePerHour;
}
}
public interface Bill {
double calculateFees(long durationInMinutes);
}
public class Car extends Vehicle {
private int numDoors;
public Car(String vehicleNum, LocalTime entryTime, int numDoors) {
super(vehicleNum, entryTime);
this.numDoors = numDoors;
}
public int getNumDoors(){
return numDoors;
}
@Override
public String getVehicleType() {
return "Car";
}
@Override
public double calculateFees(long durationInMinutes) {
double ratePerHour = 50;
if (durationInMinutes < 60 ){
durationInMinutes = 60;
}
return ((double) durationInMinutes /60) * ratePerHour;
}
}
public class MaintenanceSystem {
public void scheduleMaintenance(String task, LocalDate date) {
System.out.println("Scheduled Maintenance Task: " + task);
System.out.println("Scheduled Time: " + date);
}
public void performMaintenance(String task) {
System.out.println("Performing Maintenance Task: " + task);
System.out.println("Task Completed Successfully.");
}
public void logMaintenance(String task, LocalDate date) {
System.out.println("Maintenance Log:");
System.out.println("Task: " + task);
System.out.println("Completed at: " + date);
}
}
public class ParkingLot {
private List<ParkingSpot> spots;
private List<Ticket> tickets;
public ParkingLot(List<ParkingSpot> spots) {
this.spots = spots;
this.tickets = new ArrayList<>();
}
public List<ParkingSpot> getSpots() {
return spots;
}
public ParkingSpot assignSpot(Vehicle vehicle) {
for (ParkingSpot spot : spots) {
if (!spot.getOccupancyStatus()) {
if(!spot.isCompatibleWith(vehicle)){
Warning warning = new Warning("Incompatible vehicle type for this spot. " , vehicle, spot);
warning.displayWarning();
continue; // look for another spot.
}
spot.setOccupancyStatus(true);
return spot;
}
}
throw new IllegalStateException("We are sorry. No spot available for this vehicle type as the parking lot is full.");
}
public Ticket parkVehicle(Vehicle vehicle){
ParkingSpot spot = assignSpot(vehicle);
Ticket ticket = new Ticket(UUID.randomUUID().toString(),vehicle,spot); // using UUID to generate random ticketID and assigning vehicle and spot.
tickets.add(ticket);
return ticket;
}
public List<Ticket> getTickets() {
return tickets;
}
}
public class PaymentProcessing {
private Vehicle vehicle;
private double fee;
public void processPayment(Vehicle vehicle, double fee){
System.out.println("Processing payment for vehicle " + vehicle.getVehicleNum());
System.out.println("Amount paid " + fee + " PKR");
System.out.println("Thank you for coming. We look forward to serve you again.");
}
}
public class SafetySystem {
private ParkingLot parkingLot;
public SafetySystem(ParkingLot parkingLot){
this.parkingLot = parkingLot;
}
public void handleFire(){
System.out.println("FIRE DETECTED! Starting safety protocol.");
evacuateVehicles();
alertFireDepartment();
}
public void handleTheft(Vehicle vehicle){
System.out.println("THEFT DETECTED for vehicle " + vehicle.getVehicleNum());
alertSecurity(vehicle);
alertPolice(vehicle);
lockParkingLot();
}
public void evacuateVehicles(){
for (ParkingSpot spot : parkingLot.getSpots()){
if(spot.getOccupancyStatus()){
System.out.println("Please whoever owns " + spot.getSpotID() + " vehicle." + " start evacuating");
spot.setOccupancyStatus(false);
}
}
System.out.println("All vehicles start evacuating");
}
public void alertFireDepartment(){
System.out.println("Fire Department alerted. Help is on the way.");
}
public void alertSecurity(Vehicle vehicle){
System.out.println("Security alerted to monitor theft of vehicle " + vehicle.getVehicleNum());
}
public void alertPolice(Vehicle vehicle){
System.out.println("Police has been called and is on its way for theft of vehicle " + vehicle.getVehicleNum());
}
public void lockParkingLot(){
System.out.println("Parking Lot has been locked due to security concerns. All entry and exit points are locked.");
}
public class Ticket {
private String ticketID;
private Vehicle vehicle;
private ParkingSpot parkingSpot;
private LocalTime exitTime;
public Ticket(String ticketID, Vehicle vehicle, ParkingSpot parkingSpot) {
this.ticketID = ticketID;
this.vehicle = vehicle;
this.parkingSpot = parkingSpot;
}
public String getTicketID() {
return ticketID;
}
public void setTicketID(String ticketID) {
this.ticketID = ticketID;
}
public Vehicle getVehicle() {
return vehicle;
}
public void setVehicle(Vehicle vehicle) {
this.vehicle = vehicle;
}
public ParkingSpot getParkingSpot() {
return parkingSpot;
}
public void setParkingSpot(ParkingSpot parkingSpot) {
this.parkingSpot = parkingSpot;
}
public void setExitTime(LocalTime exitTime){
this.exitTime = exitTime;
}
public LocalTime getExitTime(){
return exitTime;
}
public String calculateDuration() {
if (vehicle.getEntryTime()!= null && exitTime != null) {
Duration duration = Duration.between(vehicle.getEntryTime(), exitTime); // Use Vehicle's entry time and exit time
long hoursTime = duration.toHours();
long minutesTime = duration.toMinutes();
return hoursTime + "hours, " + minutesTime + " minutes." ;
} else {
throw new IllegalStateException("Entry or exit timestamp not set.");
}
}
}
public class Truck extends Vehicle{
private double cargoCapacity;
public Truck(String vehicleNum, LocalTime entryTime, double cargoCapacity) {
super(vehicleNum, entryTime);
this.cargoCapacity = cargoCapacity;
}
public double getCargoCapacity(){
return cargoCapacity;
}
@Override
public String getVehicleType() {
return "Truck";
}
public double calculateFees(long durationInMinutes) {
double ratePerHour = 100;
if (durationInMinutes < 60 ){
durationInMinutes = 60;
}
return ((double)durationInMinutes/60) * ratePerHour;
}
}
public abstract class Vehicle implements Bill {
protected String vehicleNum;
protected LocalTime entryTime;
public Vehicle(String vehicleNum, LocalTime entryTime){
this.vehicleNum = vehicleNum;
this.entryTime = entryTime;
}
public String getVehicleNum() {
return vehicleNum;
}
public void setVehicleNum(String vehicleNum) {
this.vehicleNum = vehicleNum;
}
public LocalTime getEntryTime() {
return entryTime;
}
public void setEntryTime(LocalTime entryTime) {
this.entryTime = entryTime;
}
public abstract String getVehicleType();
}
}
public class Warning {
private String message;
private Vehicle vehicle;
private ParkingSpot parkingSpot;
public Warning(String message, Vehicle vehicle, ParkingSpot parkingSpot) {
this.message = message;
this.vehicle = vehicle;
this.parkingSpot = parkingSpot;
}
public String getMessage() {
return message;
}
public Vehicle getVehicle() {
return vehicle;
}
public ParkingSpot getParkingSpot() {
return parkingSpot;
}
public void displayWarning(){
System.out.println("SpotID: " + parkingSpot.getSpotID());
System.out.println(message);
System.out.println("Vehicle " + vehicle.getVehicleType() + " (" + vehicle.getVehicleNum() + ")" );
}
}
}