forked from Mohammed-3tef/Student_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.java
More file actions
261 lines (211 loc) · 11.9 KB
/
App.java
File metadata and controls
261 lines (211 loc) · 11.9 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
// Author: Mohammad Atef Abd El-Kader
// ID: 20231143
// Section: S14
// TA: Mostafa Hesham
// Date: DONE on 26/02/2025 (Alhamdulillah...)
// Description: The main class of the Student Management System Application
// that contains the main function to run the application.
// ---------------------------------------------- IMPORTS ----------------------------------------------
import java.util.*;
import packages.system.*;
import packages.fileHandler.*;
// ---------------------------------------------- MAIN FUNCTION ----------------------------------------------
public class App {
public static void main(String[] args) {
System.out.println("\n\t===> Welcome To Student Management System Application... <===\n");
Scanner scanner = new Scanner(System.in);
StudentSystem system = new StudentSystem();
while (true) {
System.out.println("Choose an option:");
System.out.println(" 1. Add Student.");
System.out.println(" 2. Remove Student.");
System.out.println(" 3. Update Student.");
System.out.println(" 4. Search Student by ID.");
System.out.println(" 5. List and Sort Students.");
System.out.println(" 6. Filter Students.");
System.out.println(" 7. Count Total Students.");
System.out.println(" 8. Calculate Average GPA.");
System.out.println(" 9. Display Top 5 Students.");
System.out.println(" 10. Display Failing Students.");
System.out.println(" 11. Generate Summary.");
System.out.println(" 0. Exit Application.");
int choice = InputValidator.inputValidChoice(scanner);
System.out.println();
switch (choice) {
case 1: // Add Student
while (true) {
System.out.println("Choose an option to add student:");
System.out.println(" 1. Add Student from CSV File.");
System.out.println(" 2. Add Student Manually.");
System.out.println(" 0. Exit Add Student.");
int addChoice = InputValidator.inputValidChoice(scanner);
if (addChoice == 0) { // Exit Add Student
System.out.println();
break;
}
switch (addChoice) {
case 1: // Add Student from CSV File
system.mergeStudentSystem(CsvFileHandler.readCsvFile());
break;
case 2: // Add Student Manually
String name = InputValidator.addUniqueName(scanner, system);
int id = InputValidator.addUniqueID(scanner, system);
double gpa = InputValidator.inputValidGPA(scanner);
String year = InputValidator.inputValidYear(scanner);
String department = InputValidator.inputValidDepartment(scanner);
if (year.equals("First") || year.equals("Second")) department = "General";
system.addStudent(name, id, gpa, year, department, false);
break;
default: // Invalid choice
System.out.println("Invalid choice, please try again.");
}
}
break;
case 2: // Remove Student
int removeID = InputValidator.inputValidID(scanner);
system.removeStudentByID(removeID);
break;
case 3: // Update Student
int updateID = InputValidator.inputValidID(scanner);
while (true) {
System.out.println("Choose an option to update:");
System.out.println(" 1. Student's Name.");
System.out.println(" 2. Student's GPA.");
System.out.println(" 3. Student's Year.");
System.out.println(" 4. Student's Department.");
System.out.println(" 0. Exit Update.");
int updateChoice = InputValidator.inputValidChoice(scanner);
if (updateChoice == 0) { // Exit Update
System.out.println();
break;
}
switch (updateChoice) {
case 1: // Update Student's Name
String newName = InputValidator.addUniqueName(scanner, system);
system.updateStudentByID(updateID, newName, -1, null, null);
break;
case 2: // Update Student's GPA
double newGPA = InputValidator.inputValidGPA(scanner);
scanner.nextLine();
system.updateStudentByID(updateID, null, newGPA, null, null);
break;
case 3: // Update Student's Year
String newYear = InputValidator.inputValidYear(scanner);
scanner.nextLine();
system.updateStudentByID(updateID, null, -1, newYear, null);
break;
case 4: // Update Student's Department
String newDepartment = InputValidator.inputValidDepartment(scanner);
scanner.nextLine();
system.updateStudentByID(updateID, null, -1, null, newDepartment);
break;
default: // Invalid choice
System.out.println("Invalid choice, please try again.");
}
}
break;
case 4: // Search Student by ID
int searchID = InputValidator.inputValidID(scanner);
system.searchByID(searchID);
break;
case 5: // List and Sort Students
while (true) {
System.out.println("Output all students in:");
System.out.println(" 1. The Console.");
System.out.println(" 2. A File.");
System.out.println(" 0. Exit List and Sort.");
int outputChoice = InputValidator.inputValidChoice(scanner);
if (outputChoice == 0) { // Exit List and Sort
System.out.println();
break;
}
else if (outputChoice == 1) { // Output in the Console
System.out.print("Enter sorting criteria (GPA, ID, Name, Year): ");
String sortBy = scanner.nextLine();
while (!sortBy.matches("GPA|ID|Name|Year")) {
System.out.println("Invalid input. Please enter a valid sorting criteria.");
System.out.print("Enter sorting criteria (GPA, ID, Name, Year): ");
sortBy = scanner.nextLine();
}
system.listAndSortAllStudents(sortBy);
break;
}
else if (outputChoice == 2) { // Output in a File (CSV)
CsvFileHandler.writeCsvFile(system);
break;
}
else System.out.println("Invalid choice, please try again.\n"); // Invalid choice
}
break;
case 6: // Filter Students
System.out.print("Choose an option to filter (GPA - Year - Department): ");
String filterChoice = scanner.nextLine();
while (!filterChoice.matches("GPA|Year|Department")) {
System.out.println("Invalid input. Please enter a valid year.");
System.out.print("Choose an option to filter (Age - GPA - Year - Department): ");
filterChoice = scanner.nextLine();
}
switch (filterChoice) {
case "GPA":
double filterGPA = InputValidator.inputValidGPA(scanner);
System.out.println();
system.filterByGPA(filterGPA);
break;
case "Year":
String filterYear = InputValidator.inputValidYear(scanner);
System.out.println();
system.filterByYear(filterYear);
break;
case "Department":
String filterDepartment = InputValidator.inputValidDepartment(scanner);
System.out.println();
system.filterByDepartment(filterDepartment);
break;
default:
System.out.println("Invalid choice, please try again.\n");
}
break;
case 7: // Count Total Students
system.countTotalStudents();
break;
case 8: // Calculate Average GPA
system.calculateAverageGPA();
break;
case 9: // Display Top 5 Students
system.displayTop5();
break;
case 10: // Display Failing Students
system.displayFailingStudents();
break;
case 11: // Generate Summary
System.out.println("Choose an option to output generated summary:");
System.out.println(" 1. Output the Summary in the Console.");
System.out.println(" 2. Output the Summary in the Report File.");
System.out.println(" 0. Exit Summary.");
int summaryChoice = InputValidator.inputValidChoice(scanner);
if (summaryChoice == 0) { // Exit Summary
System.out.println();
break;
}
switch (summaryChoice) {
case 1: // Output the Summary in the Console
system.generateSummary();
break;
case 2: // Output the Summary in the Report File
TxtFileHandler.writeTxtFile(system);
break;
default: // Invalid choice
System.out.println("Invalid choice, please try again.");
}
break;
case 0: // Exit Application.
System.out.println("\t==> Thank you for using Student Management System Application!");
System.out.println("\t\t==> Exiting system...");
scanner.close();
return;
default: // Invalid choice
System.out.println("Invalid choice, please try again.\n");
}
}
}
}