Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit abc9dee

Browse filesBrowse files
HashMap convert to Normal Array and US008 completed
1 parent 55e8686 commit abc9dee
Copy full SHA for abc9dee

File tree

6 files changed

+369
-96
lines changed
Filter options

6 files changed

+369
-96
lines changed

‎ApplicationBasedProgram/Airline/AMS.java

Copy file name to clipboardExpand all lines: ApplicationBasedProgram/Airline/AMS.java
+116-43Lines changed: 116 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
import java.util.*;
1+
import java.util.Scanner;
22

33
public class AMS {
44

55
static Scanner sc = new Scanner(System.in);
6-
static HashMap<Integer, Customer> customerMapList = new HashMap<>();
7-
static HashMap<Integer, Carrier> carrierMapList = new HashMap<>();
6+
7+
static Customer[] customerList = new Customer[10];
8+
static Carrier[] carrierList = new Carrier[10];
9+
static Flight[] flightList = new Flight[10];
10+
11+
static int customerCount = 0;
12+
static int carrierCount = 0;
13+
static int flightCount = 0;
814

915
static Customer loggedInCustomer = null;
1016

1117
private static void registerCustomer() {
18+
if (customerCount >= 10) {
19+
System.out.println("Customer list is full. Cannot register more customers.");
20+
return;
21+
}
22+
1223
System.out.print("Enter the user name: ");
1324
String userName = sc.nextLine();
1425

@@ -17,7 +28,7 @@ private static void registerCustomer() {
1728

1829
System.out.print("Enter the phone: ");
1930
Long phone = sc.nextLong();
20-
sc.nextLine(); // Consume newline
31+
sc.nextLine();
2132

2233
System.out.print("Enter the email: ");
2334
String email = sc.nextLine();
@@ -41,99 +52,161 @@ private static void registerCustomer() {
4152
System.out.print("Enter the dob: ");
4253
String dob = sc.nextLine();
4354

44-
int userId = customerMapList.size() + 1;
55+
int userId = customerCount + 1;
4556
Customer newCustomer = new Customer(userId, userName, password, email, phone, address1, address2, city, state, zipcode, dob);
46-
customerMapList.put(userId, newCustomer);
57+
customerList[customerCount++] = newCustomer;
4758

4859
System.out.println("Registered Successfully!\nYour User ID: " + userId);
4960
}
5061

51-
private static boolean checkValidCustomer(int userId, String password) {
52-
if (customerMapList.containsKey(userId) && customerMapList.get(userId).getPassword().equals(password)) {
53-
loggedInCustomer = customerMapList.get(userId);
54-
return true;
62+
private static boolean checkValidCustomer(int userId, String password, String role) {
63+
for (Customer customer : customerList) {
64+
if (customer != null && customer.getUserId() == userId && customer.getPassword().equals(password) && customer.getRole().equals(role)) {
65+
loggedInCustomer = customer;
66+
return true;
67+
}
5568
}
5669
System.out.println("\nYou're Not Authenticated. Please Register.");
5770
return false;
5871
}
5972

6073
private static boolean login(String type) {
61-
if (type.equals("admin")) {
62-
return Admin.adminMenu();
63-
} else if (type.equals("customer")) {
64-
System.out.print("-------------------------------------------------------------------");
65-
System.out.print("\nEnter the userId: ");
66-
int userId = sc.nextInt();
67-
sc.nextLine(); // Consume newline
68-
69-
System.out.print("Enter the password: ");
70-
String password = sc.nextLine();
71-
System.out.print("-------------------------------------------------------------------");
72-
73-
if (checkValidCustomer(userId, password)) {
74+
System.out.print("-------------------------------------------------------------------");
75+
System.out.print("\nEnter the userId: ");
76+
int userId = sc.nextInt();
77+
sc.nextLine();
78+
79+
System.out.print("Enter the password: ");
80+
String password = sc.nextLine();
81+
System.out.print("-------------------------------------------------------------------");
82+
83+
if (checkValidCustomer(userId, password, type)) {
84+
if (type.equals("Admin")) {
85+
return Admin.adminMenu();
86+
} else if (type.equals("Customer")) {
7487
return Customer.customerMenu();
7588
}
7689
}
7790
return false;
7891
}
7992

8093
private static void displayCustomers() {
81-
if (customerMapList.isEmpty()) {
82-
System.out.println("\nNo Customers Registered Yet.");
94+
if (customerCount == 0) {
95+
System.out.println("\nNo User Registered Yet.");
8396
} else {
84-
System.out.println("\nList of Customers:");
85-
for (Map.Entry<Integer, Customer> map : customerMapList.entrySet()) {
97+
System.out.println("\nList of Users:");
98+
for (int i = 0; i < customerCount; i++) {
99+
Customer customer = customerList[i];
86100
System.out.println(
87-
"User ID: " + map.getValue().getUserId() +
88-
" | Name: " + map.getValue().getUserName()
101+
"User ID: " + customer.getUserId() +
102+
" | Name: " + customer.getUserName() +
103+
" | Role: " + customer.getRole() +
104+
" | Category: " + customer.getCategory()
89105
);
90106
}
91107
}
92108
}
109+
110+
private static void addDummyData() {
111+
if (customerCount < 10) {
112+
Customer user1 = new Customer(1, "pradeep", "krish", "pradeep@gmail.com",
113+
987654322L, "south", "murukanathapuram", "karur", "tamil", 639001L, "24/4/2002");
114+
user1.setRole("Customer");
115+
user1.setCategory("Silver");
116+
customerList[customerCount++] = user1;
117+
}
93118

94-
public static void main(String[] args) {
95-
// Adding default customers
96-
customerMapList.put(1, new Customer(1, "pradeep", "krish", "pradeep@gmail.com",
97-
987654322L, "south", "murukanathapuram", "karur", "tamil", 639001L, "24/4/2002"));
98-
99-
customerMapList.put(2, new Customer(2, "pradeep2", "krish2", "pradeep2@gmail.com",
100-
987654322L, "north", "somewhere", "chennai", "tamil", 600001L, "25/5/2003"));
119+
if (customerCount < 10) {
120+
Customer user2 = new Customer(2, "pradeep2", "krish2", "pradeep2@gmail.com",
121+
987654322L, "north", "somewhere", "chennai", "tamil", 600001L, "25/5/2003");
122+
user2.setRole("Admin");
123+
user2.setCategory("Gold");
124+
customerList[customerCount++] = user2;
125+
}
126+
127+
if (carrierCount < 10) {
128+
carrierList[carrierCount++] = new Carrier(1, "jet carrier", 12, 22, 33, 44, 55, 66, 77, 22, 11, 44);
129+
}
101130

131+
if (flightCount < 10) {
132+
flightList[flightCount++] = new Flight(1, 1, "chennai", "Paris", "24/02/2025", 88, 33, 44, 55);
133+
}
134+
}
135+
136+
private static void searchFlight() {
137+
System.out.print("Enter Origin: ");
138+
String origin = sc.nextLine();
139+
140+
System.out.print("Enter Destination: ");
141+
String destination = sc.nextLine();
142+
143+
System.out.print("Enter Travel Date: ");
144+
String travelDate = sc.nextLine();
145+
146+
Flight findSearchFlight = null;
147+
148+
for (int i = 0; i < flightCount; i++) {
149+
Flight flight = flightList[i];
150+
if (flight.getOrigin().equalsIgnoreCase(origin) && flight.getDestination().equalsIgnoreCase(destination) && flight.getTravelDate().equalsIgnoreCase(travelDate)) {
151+
findSearchFlight = flight;
152+
break;
153+
}
154+
}
155+
156+
if (findSearchFlight == null) {
157+
System.out.println("\nNo Flights Yet.");
158+
} else {
159+
System.out.println("\nList of Flights:");
160+
System.out.println(
161+
"Flight ID: " + findSearchFlight.getFlightId() +
162+
" | Carrier ID: " + findSearchFlight.getCarrierId()
163+
);
164+
}
165+
}
166+
167+
public static void main(String[] args) {
168+
addDummyData();
102169
int n;
103170
do {
104171
System.out.println("\n-------------------------------------------------------------------");
172+
System.out.println("Main Menu");
105173
System.out.println("1. Admin Sign-in");
106174
System.out.println("2. Customer Sign-in");
107175
System.out.println("3. Customer Registration");
108-
System.out.println("4. Display Customer List");
109-
System.out.println("5. Exit");
176+
System.out.println("4. Search Flight");
177+
System.out.println("5. Display Users List");
178+
System.out.println("6. Exit");
110179
System.out.println("-------------------------------------------------------------------");
111180
System.out.print("Enter the operation: ");
112181

113182
n = sc.nextInt();
114-
sc.nextLine(); // Consume newline
183+
sc.nextLine();
115184

116185
switch (n) {
117186
case 1:
118187
System.out.println("Admin sign-in");
119-
if (login("admin")) System.exit(0);
188+
if (login("Admin")) System.exit(0);
120189
break;
121190

122191
case 2:
123192
System.out.println("Customer sign-in");
124-
if (login("customer")) System.exit(0);
193+
if (login("Customer")) System.exit(0);
125194
break;
126195

127196
case 3:
128197
System.out.println("Customer Registration");
129198
registerCustomer();
130199
break;
131-
132200
case 4:
133-
displayCustomers();
201+
System.out.println("Search Flight");
202+
searchFlight();
134203
break;
135204

136205
case 5:
206+
displayCustomers();
207+
break;
208+
209+
case 6:
137210
System.out.println("Exiting the program...");
138211
System.exit(0);
139212
break;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.