-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPMSApp.java
More file actions
126 lines (106 loc) · 5.56 KB
/
Copy pathAPMSApp.java
File metadata and controls
126 lines (106 loc) · 5.56 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
// CHANGES NEED TO BE MADE
// 1. after user enters wrong ID, program shouldnt go to top level menu
// - instead program needs to ask user for input again and provide a key to go back to top-level menu
// example: enter 0 to go back to the main menu
// 2. Do some small error handling and make the program more intuitive
import java.util.Scanner;
public class APMSApp {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
// initialize variables
int user_choice;
boolean continueLoop = true;
// Display menu
System.out.println("Welcome to the Ashesi Parking System.");
System.out.println("1) Staff");
System.out.println("2) Student");
System.out.println("3) Visitor");
System.out.println("4) Exit");
// do while loop here to make sure user inputs are valid
do {
System.out.print("\nYour input: ");
// try catch exception to check if user enters letter instead of a number
try {
// this line selects the integer from the options the user enters
user_choice = Integer.parseInt(scanner.nextLine());
switch (user_choice) {
case 1:
System.out.println("Enter your Staff ID: ");
String staffID = scanner.nextLine();
User user = new User(staffID, "staff"); // create an instance of the User class
if (user.verifyStaffID(staffID)){
System.out.println("ID is valid.");
// Display menu
user.displayMenu(); // changed to handle - own output and operations
} else {
System.out.println("Invalid ID. Please try again.");
};
case 2:
System.out.println("Enter your Student ID: ");
String studentID = scanner.nextLine();
User user1 = new User(studentID, "student"); // create an instance of the User class
if (user1.verifyStaffID(studentID)){
System.out.println("ID is valid.");
// Display menu
user1.displayMenu(); // changed to handle - own output and operations
} else {
System.out.println("Invalid ID. Please try again.");
};
break;
case 3:
System.out.println("Enter your Vi ID: ");
String visitorID = scanner.nextLine();
User user2 = new User(visitorID, "vissitor"); // create an instance of the User class
if (user2.verifyStaffID(visitorID)){
System.out.println("ID is valid.");
// Display menu
user2.displayMenu(); // changed to handle - own output and operations
} else {
System.out.println("Invalid ID. Please try again.");
};
case 4:
System.out.println("Thank you for using the Ashesi Parking system.");
continueLoop = false; // Change continueLoop to false if user wants to exit
break;
default:
// System.out.println("Invalid Option. Please try again");
System.out.println("Back to main menu");
break;
}
} catch (NumberFormatException e) {
System.out.println("Invalid Input. Please enter a number."); //
}
} while (continueLoop);
scanner.close();
}
}
// @ Reggie and Lois --- do same for the studrnt, visitor...
// case 2:
// System.out.println("Enter your parking permit.");
// String studentPermit = scanner.nextLine();
// studentPermit = studentPermit.toUpperCase();
// if(!studentPermit.startsWith("STU")){
// System.out.println("Invalid Parking Permit");
// } else{
// System.out.println("Where on campus are you going or which carpark do you wish to park at?");
// System.out.println("");
// String choice = scanner.nextLine();
// choice = choice.toUpperCase();
// if(choice.startsWith("FAB")){
// //pick from fablab array
// }else if(choice.startsWith("M")){
// //choose from the maincarpark array
// }
// }
// // Reggie - see
// private static void handleParking(Scanner scanner) {
// Booking.displayAvailableSpots(); // Assuming Booking class has this static method to display spots
// System.out.println("Select a parking spot ID (e.g., MPC 01):");
// String spotId = scanner.nextLine();
// System.out.println("Select a time (e.g., 10am):");
// String time = scanner.nextLine();
// if (Booking.reserveParkingSpot(spotId, time)) {
// System.out.println("Parking reserved successfully for " + spotId + " at " + time);
// } else {
// System.out.println("Failed to reserve parking. Please try again or select a different spot/time.");
// }