-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
207 lines (172 loc) · 6.99 KB
/
Main.java
File metadata and controls
207 lines (172 loc) · 6.99 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
/**
*
* AIRLINES RESERVATION SYSTEM
* Master : Dr.Shokoofeh_Bostan
* Programmer : Ali_Nejati
* @alineejati
* April-2023
*
*/
import java.util.*;
public class Main {
static Passenger[] passenger = new Passenger[15];
static Admin admin = new Admin();
/**
* This function has three sections: Sign in, Sign up and Exit from the program,
* which according to the user's choice, the program runs in a certain direction.
*/
public static void main(String[] args) {
System.out.print("\033[H\033[2J");
System.out.flush();
admin.flightManagementList();
Scanner input = new Scanner(System.in);
int command;
while (true){
System.out.print("\033[H\033[2J");
System.out.flush();
System.out.println("::::::::::::::::::::::::::::::::::::::::::::::: \n\t" +
"WELCOME TO NEJATI AIRLINE SYSTEM\t\n" +
"::::::::::::::::::::::::::::::::::::::::::::::: \n" +
"..............MENU OPTION...................... \n" +
"::::::::::::::::::::::::::::::::::::::::::::::: \n" +
"1.Sign in \n2.Sign up \n3.Exit");
System.out.print("Enter Your command : ");
command = input.nextInt();
switch (command) {
case 1:
signIn();
break;
case 2:
signUp();
break;
case 3:
exitApp();
break;
}
}
}
/**
* This function is for when the user logs in for the first time and must Sign up,
* and the point of this function is that the username and password values cannot be empty.
* Also, if the username is already registered in the system, it is not acceptable...
*/
public static void signUp(){
Scanner input = new Scanner(System.in);
System.out.print("\033[H\033[2J");
System.out.flush();
String username = null;
String password = null;
for(int i = 0 ; i < Main.passenger.length ; i++){
if (Main.passenger[i] == null){
System.out.print("Please Enter your Username : ");
username = input.nextLine();
while (searchPassenger(username) == 1 || username.length() == 0){
if (searchPassenger(username) == 1){
System.out.println("This username already exists");
}
if (username.length() == 0){
System.out.println("The Username cannot be empty !");
}
System.out.print("Please Enter another Username : ");
username = input.nextLine();
}
System.out.print("Please Enter your Password : ");
password = input.nextLine();
while (password.length() == 0){
System.out.println("The password cannot be empty !");
System.out.print("Please Enter your Password : ");
password = input.nextLine();
}
Main.passenger[i] = new Passenger(username,password);
System.out.println("Dear << " + username + " >> Your account has been successfully created ...");
System.out.println("Welcome to our big family :)");
break;
}
}
System.out.print("Please Enter any key to continue : ");
input.nextLine();
}
/**
* This function is for when the user has Sign up before and now wants to enter his account
*/
public static void signIn(){
Scanner input = new Scanner(System.in);
System.out.print("\033[H\033[2J");
System.out.flush();
String username = null;
String password = null;
boolean flag = false;
System.out.print("Please Enter your Username : ");
username = input.nextLine();
System.out.print("Please Enter your password : ");
password = input.nextLine();
if(username.toLowerCase().equals(admin.usernameAdmin)){
if (password.toLowerCase().equals(admin.passwordAdmin)){
admin.adminMenu();
flag = true;
}
else {
System.out.println("Your password is << admin >> Please try again...");
System.out.print("Please Enter any key to continue : ");
input.nextLine();
flag = true;
}
}
for (int i = 0; i < passenger.length; i++) {
if (passenger[i] != null && passenger[i].getUsernamePassenger().equals(username)){
if (passenger[i].getPasswordPassenger().equals(password)){
passenger[i].passengerMenu();
flag = true;
}
else {
System.out.println("Your password is incorrect. Please try again ...");
System.out.print("Please Enter any key to continue : ");
input.nextLine();
flag = true;
}
}
}
if (flag == false){
System.out.println("Oooops , No such user found. Please sign up first !");
System.out.print("Please Enter any key to continue : ");
input.nextLine();
}
}
/**
* This function compares the entered username with all the usernames registered in the system,
* and if it exists in the system, it does not allow the user to choose it.
*/
public static int searchPassenger(String username){
for (int i = 0; i < Main.passenger.length; i++) {
if (Main.passenger[i] != null && Main.passenger[i].getUsernamePassenger().equals(username)){
return 1;
}
}
return -1;
}
/**
* Calling this function closes the program
*/
public static void exitApp(){
System.out.print("Goodbye dear\n" + "Hoping to see you again...");
System.exit(0);
}
}
/**
* آه یکی بود یکی نبود یه عاشقی بود که یه روز
* بهت میگفت دوست داره آخ که دوست داره هنوز
* دلم یه دیوونه شده ، واست بی آزاره هنوز
* از دل دیوونه نترس آخ که دوست داره هنوز
* وای که دوست داره هنوز
* شب که میشه به عشق تو غزل غزل صدا میشم
* ترانه خون قصه ی تموم عاشقا میشم
* @alineejati
* @ebi
*گفتی
* که با وفا بشم سهم من از وفا تویی
* سهم من از خودم تویی سهم من از خدا تویی
* گفتی که دلتنگی نکن آخ مگه میشه نازنین
* حال پریشون منو ندیدی و بیا ببین
* شب که می شه به عشق تو غزل غزل صدا می شم
* ترانه خون قصه ی تموم عاشقا می شم
*/