1
- import java .util .* ;
1
+ import java .util .Scanner ;
2
2
3
3
public class AMS {
4
4
5
5
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 ;
8
14
9
15
static Customer loggedInCustomer = null ;
10
16
11
17
private static void registerCustomer () {
18
+ if (customerCount >= 10 ) {
19
+ System .out .println ("Customer list is full. Cannot register more customers." );
20
+ return ;
21
+ }
22
+
12
23
System .out .print ("Enter the user name: " );
13
24
String userName = sc .nextLine ();
14
25
@@ -17,7 +28,7 @@ private static void registerCustomer() {
17
28
18
29
System .out .print ("Enter the phone: " );
19
30
Long phone = sc .nextLong ();
20
- sc .nextLine (); // Consume newline
31
+ sc .nextLine ();
21
32
22
33
System .out .print ("Enter the email: " );
23
34
String email = sc .nextLine ();
@@ -41,99 +52,161 @@ private static void registerCustomer() {
41
52
System .out .print ("Enter the dob: " );
42
53
String dob = sc .nextLine ();
43
54
44
- int userId = customerMapList . size () + 1 ;
55
+ int userId = customerCount + 1 ;
45
56
Customer newCustomer = new Customer (userId , userName , password , email , phone , address1 , address2 , city , state , zipcode , dob );
46
- customerMapList . put ( userId , newCustomer ) ;
57
+ customerList [ customerCount ++] = newCustomer ;
47
58
48
59
System .out .println ("Registered Successfully!\n Your User ID: " + userId );
49
60
}
50
61
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
+ }
55
68
}
56
69
System .out .println ("\n You're Not Authenticated. Please Register." );
57
70
return false ;
58
71
}
59
72
60
73
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 ( " \n Enter 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 ( " \n Enter 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" )) {
74
87
return Customer .customerMenu ();
75
88
}
76
89
}
77
90
return false ;
78
91
}
79
92
80
93
private static void displayCustomers () {
81
- if (customerMapList . isEmpty () ) {
82
- System .out .println ("\n No Customers Registered Yet." );
94
+ if (customerCount == 0 ) {
95
+ System .out .println ("\n No User Registered Yet." );
83
96
} else {
84
- System .out .println ("\n List of Customers:" );
85
- for (Map .Entry <Integer , Customer > map : customerMapList .entrySet ()) {
97
+ System .out .println ("\n List of Users:" );
98
+ for (int i = 0 ; i < customerCount ; i ++) {
99
+ Customer customer = customerList [i ];
86
100
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 ()
89
105
);
90
106
}
91
107
}
92
108
}
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
+ }
93
118
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
+ }
101
130
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 ("\n No Flights Yet." );
158
+ } else {
159
+ System .out .println ("\n List 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 ();
102
169
int n ;
103
170
do {
104
171
System .out .println ("\n -------------------------------------------------------------------" );
172
+ System .out .println ("Main Menu" );
105
173
System .out .println ("1. Admin Sign-in" );
106
174
System .out .println ("2. Customer Sign-in" );
107
175
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" );
110
179
System .out .println ("-------------------------------------------------------------------" );
111
180
System .out .print ("Enter the operation: " );
112
181
113
182
n = sc .nextInt ();
114
- sc .nextLine (); // Consume newline
183
+ sc .nextLine ();
115
184
116
185
switch (n ) {
117
186
case 1 :
118
187
System .out .println ("Admin sign-in" );
119
- if (login ("admin " )) System .exit (0 );
188
+ if (login ("Admin " )) System .exit (0 );
120
189
break ;
121
190
122
191
case 2 :
123
192
System .out .println ("Customer sign-in" );
124
- if (login ("customer " )) System .exit (0 );
193
+ if (login ("Customer " )) System .exit (0 );
125
194
break ;
126
195
127
196
case 3 :
128
197
System .out .println ("Customer Registration" );
129
198
registerCustomer ();
130
199
break ;
131
-
132
200
case 4 :
133
- displayCustomers ();
201
+ System .out .println ("Search Flight" );
202
+ searchFlight ();
134
203
break ;
135
204
136
205
case 5 :
206
+ displayCustomers ();
207
+ break ;
208
+
209
+ case 6 :
137
210
System .out .println ("Exiting the program..." );
138
211
System .exit (0 );
139
212
break ;
0 commit comments