-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartParkApplication.java
More file actions
177 lines (155 loc) · 7.25 KB
/
Copy pathSmartParkApplication.java
File metadata and controls
177 lines (155 loc) · 7.25 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
package com.parking;
import com.parking.model.*;
import com.parking.service.ParkingLotService;
import java.util.Map;
import java.util.Scanner;
/**
* SmartPark — Intelligent Parking Management System
* CLI demo runner for the Java backend.
*/
public class SmartParkApplication {
private static final ParkingLotService lotService = new ParkingLotService();
public static void main(String[] args) {
System.out.println("╔══════════════════════════════════════════╗");
System.out.println("║ SMARTPARK — Intelligent Parking ║");
System.out.println("║ Management System v1.0 ║");
System.out.println("╚══════════════════════════════════════════╝");
System.out.println();
// Demo: Simulate entries and exits
runDemo();
}
private static void runDemo() {
Scanner scanner = new Scanner(System.in);
boolean running = true;
while (running) {
printMenu();
System.out.print("Select option: ");
String choice = scanner.nextLine().trim();
switch (choice) {
case "1":
vehicleEntry(scanner);
break;
case "2":
vehicleExit(scanner);
break;
case "3":
viewAvailableSpots();
break;
case "4":
viewAnalytics();
break;
case "5":
viewTicketHistory();
break;
case "6":
runAutomaticDemo();
break;
case "0":
running = false;
System.out.println("\n👋 Thank you for using SmartPark!");
break;
default:
System.out.println("❌ Invalid option. Try again.");
}
}
scanner.close();
}
private static void printMenu() {
System.out.println("\n┌─────────────────────────────────────┐");
System.out.println("│ 1. Vehicle Entry │");
System.out.println("│ 2. Vehicle Exit │");
System.out.println("│ 3. View Available Spots │");
System.out.println("│ 4. Analytics Dashboard │");
System.out.println("│ 5. Ticket History │");
System.out.println("│ 6. Run Automatic Demo │");
System.out.println("│ 0. Exit │");
System.out.println("└─────────────────────────────────────┘");
}
private static void vehicleEntry(Scanner scanner) {
System.out.print("License Plate: ");
String plate = scanner.nextLine().trim().toUpperCase();
System.out.print("Owner Name: ");
String owner = scanner.nextLine().trim();
System.out.println("Vehicle Type: 1=CAR 2=MOTORCYCLE 3=TRUCK 4=EV 5=HANDICAPPED");
System.out.print("Choice: ");
int typeChoice = Integer.parseInt(scanner.nextLine().trim());
Vehicle.VehicleType[] types = Vehicle.VehicleType.values();
Vehicle.VehicleType type = types[Math.min(typeChoice - 1, types.length - 1)];
try {
ParkingTicket ticket = lotService.processEntry(plate, owner, type);
System.out.println("\n✅ Entry Successful!");
System.out.println(" Ticket ID : " + ticket.getTicketId());
System.out.println(" Spot : " + ticket.getSpotId());
System.out.println(" Entry Time : " + ticket.getIssuedAt());
} catch (Exception e) {
System.out.println("❌ " + e.getMessage());
}
}
private static void vehicleExit(Scanner scanner) {
System.out.print("License Plate: ");
String plate = scanner.nextLine().trim().toUpperCase();
try {
ParkingTicket ticket = lotService.processExit(plate);
System.out.println("\n✅ Exit Processed!");
System.out.println(" Ticket ID : " + ticket.getTicketId());
System.out.println(" Duration : " + ticket.getDurationMinutes() + " minutes");
System.out.println(" Amount Due : ₹" + String.format("%.2f", ticket.getAmount()));
System.out.println(" Status : " + (ticket.isPaid() ? "PAID ✓" : "PENDING"));
} catch (Exception e) {
System.out.println("❌ " + e.getMessage());
}
}
private static void viewAvailableSpots() {
System.out.println("\n📍 Available Spots:");
System.out.printf("%-8s %-6s %-8s %-15s%n", "Spot ID", "Zone", "Level", "Type");
System.out.println("─".repeat(45));
lotService.getAvailableSpots().stream().limit(20).forEach(spot ->
System.out.printf("%-8s %-6s %-8d %-15s%n",
spot.getId(), spot.getZone(), spot.getLevel(), spot.getType())
);
System.out.println("\nTotal Available: " + lotService.getAvailableSpots().size());
}
private static void viewAnalytics() {
System.out.println("\n📊 Analytics Dashboard");
System.out.println("─".repeat(40));
Map<String, Object> analytics = lotService.getAnalytics();
analytics.forEach((k, v) -> System.out.printf(" %-20s : %s%n", k, v));
}
private static void viewTicketHistory() {
System.out.println("\n🎫 Ticket History (last 10):");
lotService.getTicketHistory().stream()
.skip(Math.max(0, lotService.getTicketHistory().size() - 10))
.forEach(System.out::println);
}
private static void runAutomaticDemo() {
System.out.println("\n🚀 Running automatic demo...\n");
String[][] vehicles = {
{"MH12AB1234", "Rahul Sharma", "1"},
{"DL05CD5678", "Priya Singh", "4"},
{"KA03EF9012", "Amit Kumar", "5"},
{"TN22GH3456", "Meera Nair", "2"},
{"GJ01IJ7890", "Vikram Patel", "3"},
};
// Entries
for (String[] v : vehicles) {
try {
Vehicle.VehicleType type = Vehicle.VehicleType.values()[Integer.parseInt(v[2]) - 1];
ParkingTicket ticket = lotService.processEntry(v[0], v[1], type);
System.out.printf(" ✓ %s → Spot %s%n", v[0], ticket.getSpotId());
} catch (Exception e) {
System.out.println(" ❌ " + e.getMessage());
}
}
System.out.println("\n--- Processing exits ---");
// Exit first 3
for (int i = 0; i < 3; i++) {
try {
ParkingTicket t = lotService.processExit(vehicles[i][0]);
System.out.printf(" ✓ %s exited | Charge: ₹%.2f%n", vehicles[i][0], t.getAmount());
} catch (Exception e) {
System.out.println(" ❌ " + e.getMessage());
}
}
viewAnalytics();
}
}