1+ import java .util .*;
2+ import packages .system .*;
3+ import packages .fileHandler .*;
4+
5+ // ---------------------------------------------- MAIN FUNCTION ----------------------------------------------
6+
7+ public class App {
8+ public static void main (String [] args ) {
9+ System .out .println ("\n \t ------------ WELCOME TO STUDENT MANAGEMENT SYSTEM ------------\n " );
10+ Scanner scanner = new Scanner (System .in );
11+ StudentSystem system = new StudentSystem ();
12+
13+ while (true ) {
14+ System .out .println ("Choose an option:" );
15+ System .out .println (" 1. Add Student." );
16+ System .out .println (" 2. Remove Student." );
17+ System .out .println (" 3. Update Student." );
18+ System .out .println (" 4. Search Student by ID." );
19+ System .out .println (" 5. List and Sort Students." );
20+ System .out .println (" 6. Filter Students." );
21+ System .out .println (" 7. Count Total Students." );
22+ System .out .println (" 8. Calculate Average GPA." );
23+ System .out .println (" 9. Display Top 5 Students." );
24+ System .out .println (" 10. Display Failing Students." );
25+ System .out .println (" 11. Generate Summary." );
26+ System .out .println (" 0. Exit Application." );
27+
28+ int choice = InputValidator .inputValidChoice (scanner );
29+ System .out .println ();
30+
31+ switch (choice ) {
32+ case 1 : // Add Student
33+ while (true ) {
34+ System .out .println ("Choose an option to add student:" );
35+ System .out .println (" 1. Add Student from CSV File." );
36+ System .out .println (" 2. Add Student Manually." );
37+ System .out .println (" 0. Exit Add Student." );
38+
39+ int addChoice = InputValidator .inputValidChoice (scanner );
40+
41+ if (addChoice == 0 ) { // Exit Add Student
42+ System .out .println ();
43+ break ;
44+ }
45+
46+ switch (addChoice ) {
47+ case 1 : // Add Student from CSV File
48+ system .mergeStudentSystem (CsvFileHandler .readCsvFile ());
49+ break ;
50+
51+ case 2 : // Add Student Manually
52+ String name = InputValidator .addUniqueName (scanner , system );
53+ int id = InputValidator .addUniqueID (scanner , system );
54+ double gpa = InputValidator .inputValidGPA (scanner );
55+ String year = InputValidator .inputValidYear (scanner );
56+ String department = InputValidator .inputValidDepartment (scanner );
57+
58+ if (year .equals ("First" ) || year .equals ("Second" )) department = "General" ;
59+
60+ system .addStudent (name , id , gpa , year , department , false );
61+ break ;
62+
63+ default : // Invalid choice
64+ System .out .println ("Invalid choice, please try again." );
65+ }
66+ }
67+ break ;
68+
69+ case 2 : // Remove Student
70+ int removeID = InputValidator .inputValidID (scanner );
71+ system .removeStudentByID (removeID );
72+ break ;
73+
74+ case 3 : // Update Student
75+ int updateID = InputValidator .inputValidID (scanner );
76+
77+ while (true ) {
78+ System .out .println ("Choose an option to update:" );
79+ System .out .println (" 1. Student's Name." );
80+ System .out .println (" 2. Student's GPA." );
81+ System .out .println (" 3. Student's Year." );
82+ System .out .println (" 4. Student's Department." );
83+ System .out .println (" 0. Exit Update." );
84+
85+ int updateChoice = InputValidator .inputValidChoice (scanner );
86+ if (updateChoice == 0 ) { // Exit Update
87+ System .out .println ();
88+ break ;
89+ }
90+
91+ switch (updateChoice ) {
92+ case 1 : // Update Student's Name
93+ String newName = InputValidator .addUniqueName (scanner , system );
94+ system .updateStudentByID (updateID , newName , -1 , null , null );
95+ break ;
96+
97+ case 2 : // Update Student's GPA
98+ double newGPA = InputValidator .inputValidGPA (scanner );
99+ scanner .nextLine ();
100+ system .updateStudentByID (updateID , null , newGPA , null , null );
101+ break ;
102+
103+ case 3 : // Update Student's Year
104+ String newYear = InputValidator .inputValidYear (scanner );
105+ scanner .nextLine ();
106+ system .updateStudentByID (updateID , null , -1 , newYear , null );
107+ break ;
108+
109+ case 4 : // Update Student's Department
110+ String newDepartment = InputValidator .inputValidDepartment (scanner );
111+ scanner .nextLine ();
112+ system .updateStudentByID (updateID , null , -1 , null , newDepartment );
113+ break ;
114+
115+ default : // Invalid choice
116+ System .out .println ("Invalid choice, please try again." );
117+ }
118+ }
119+
120+ break ;
121+
122+ case 4 : // Search Student by ID
123+ int searchID = InputValidator .inputValidID (scanner );
124+ system .searchByID (searchID );
125+ break ;
126+
127+ case 5 : // List and Sort Students
128+ while (true ) {
129+ System .out .println ("Output all students in:" );
130+ System .out .println (" 1. The Console." );
131+ System .out .println (" 2. A File." );
132+ System .out .println (" 0. Exit List and Sort." );
133+
134+ int outputChoice = InputValidator .inputValidChoice (scanner );
135+
136+ if (outputChoice == 0 ) { // Exit List and Sort
137+ System .out .println ();
138+ break ;
139+ }
140+
141+ else if (outputChoice == 1 ) { // Output in the Console
142+ System .out .print ("Enter sorting criteria (GPA, ID, Name, Year): " );
143+ String sortBy = scanner .nextLine ();
144+
145+ while (!sortBy .matches ("GPA|ID|Name|Year" )) {
146+ System .out .println ("Invalid input. Please enter a valid sorting criteria." );
147+ System .out .print ("Enter sorting criteria (GPA, ID, Name, Year): " );
148+ sortBy = scanner .nextLine ();
149+ }
150+
151+ system .listAndSortAllStudents (sortBy );
152+ break ;
153+ }
154+
155+ else if (outputChoice == 2 ) { // Output in a File (CSV)
156+ CsvFileHandler .writeCsvFile (system );
157+ break ;
158+ }
159+
160+ else System .out .println ("Invalid choice, please try again.\n " ); // Invalid choice
161+ }
162+ break ;
163+
164+ case 6 : // Filter Students
165+ System .out .print ("Choose an option to filter (GPA - Year - Department): " );
166+ String filterChoice = scanner .nextLine ();
167+
168+ while (!filterChoice .matches ("GPA|Year|Department" )) {
169+ System .out .println ("Invalid input. Please enter a valid year." );
170+ System .out .print ("Choose an option to filter (Age - GPA - Year - Department): " );
171+ filterChoice = scanner .nextLine ();
172+ }
173+
174+ switch (filterChoice ) {
175+ case "GPA" :
176+ double filterGPA = InputValidator .inputValidGPA (scanner );
177+ System .out .println ();
178+ system .filterByGPA (filterGPA );
179+ break ;
180+
181+ case "Year" :
182+ String filterYear = InputValidator .inputValidYear (scanner );
183+ System .out .println ();
184+ system .filterByYear (filterYear );
185+ break ;
186+
187+ case "Department" :
188+ String filterDepartment = InputValidator .inputValidDepartment (scanner );
189+ System .out .println ();
190+ system .filterByDepartment (filterDepartment );
191+ break ;
192+
193+ default :
194+ System .out .println ("Invalid choice, please try again.\n " );
195+ }
196+ break ;
197+
198+ case 7 : // Count Total Students
199+ system .countTotalStudents ();
200+ break ;
201+
202+ case 8 : // Calculate Average GPA
203+ system .calculateAverageGPA ();
204+ break ;
205+
206+ case 9 : // Display Top 5 Students
207+ system .displayTop5 ();
208+ break ;
209+
210+ case 10 : // Display Failing Students
211+ system .displayFailingStudents ();
212+ break ;
213+
214+ case 11 : // Generate Summary
215+ System .out .println ("Choose an option to output generated summary:" );
216+ System .out .println (" 1. Output the Summary in the Console." );
217+ System .out .println (" 2. Output the Summary in the Report File." );
218+ System .out .println (" 0. Exit Summary." );
219+
220+ int summaryChoice = InputValidator .inputValidChoice (scanner );
221+ if (summaryChoice == 0 ) { // Exit Summary
222+ System .out .println ();
223+ break ;
224+ }
225+
226+ switch (summaryChoice ) {
227+ case 1 : // Output the Summary in the Console
228+ system .generateSummary ();
229+ break ;
230+
231+ case 2 : // Output the Summary in the Report File
232+ TxtFileHandler .writeTxtFile (system );
233+ break ;
234+
235+ default : // Invalid choice
236+ System .out .println ("Invalid choice, please try again." );
237+ }
238+ break ;
239+
240+ case 0 : // Exit Application.
241+ System .out .println ("--- Thank you for using Student Management System Application!" );
242+ System .out .println ("\t --- Exiting system..." );
243+ scanner .close ();
244+ return ;
245+
246+ default : // Invalid choice
247+ System .out .println ("Invalid choice, please try again.\n " );
248+ }
249+ }
250+ }
251+ }
0 commit comments