-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseRegistrationSystem.java
More file actions
318 lines (286 loc) · 9.62 KB
/
CourseRegistrationSystem.java
File metadata and controls
318 lines (286 loc) · 9.62 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
public class CourseRegistrationSystem {
private static ArrayList<Course> allCourses = new ArrayList<Course>();
private static ArrayList<Course> fullCourses = new ArrayList<Course>();
private static ArrayList<Student> allStudents = new ArrayList<Student>();
private static Student loggedStudent;
public static void main(String[] args) throws FileNotFoundException {
//DE-SERIALIZATION
try{
FileInputStream fis1 = new FileInputStream("All_Courses.ser");
ObjectInputStream ois1 = new ObjectInputStream(fis1);
allCourses = (ArrayList<Course>) ois1.readObject();
FileInputStream fis2 = new FileInputStream("All_Students.ser");
ObjectInputStream ois2 = new ObjectInputStream(fis2);
allStudents = (ArrayList<Student>) ois2.readObject();
ois1.close();
fis1.close();
ois2.close();
fis2.close();
}
catch(Exception e){
//read CSV file
addCoursesToSystem();
}
Admin admin = new Admin("Admin", "Admin001", "Admin", "Adminson");
Scanner input = new Scanner(System.in);
System.out.println("Admin or Student?");
String response = input.nextLine();
if (response.toLowerCase().equals("admin")) {
boolean keepgoing = true;
while (keepgoing == true) {
System.out.println("Please enter your login information.");
System.out.println("Username: ");
String username = input.nextLine();
System.out.println("Password: ");
String password = input.nextLine();
//check if Admin login info is correct
if (username.equals("Admin") && password.equals("Admin001")) {
keepgoing = false; //exit loop
}
else {
System.out.println("");
System.out.println("Wrong username or password");
keepgoing = true;
}
}
System.out.println("");
System.out.println("");
//loop to keep Admin Menu running
boolean keepgoingAdminMenu = true;
while (keepgoingAdminMenu == true) {
//Admin Menu
System.out.println("1.Course Management");
System.out.println("2.Reports");
System.out.println("3.Exit");
String adminResponse = input.nextLine();
switch (adminResponse) {
//COURSE MANAGEMENT
case "1":
//loop to keep Course Management Menu running
boolean keepgoingManagement = true;
while (keepgoingManagement == true) {
//COURSE MANAGEMENT MENU
System.out.println("");
System.out.println("COURSE MANAGEMENT");
System.out.println("");
System.out.println("1.Create a new course");
System.out.println("2.Delete a course");
System.out.println("3.Edit a course");
System.out.println("4.Display information for a given course (by course ID)");
System.out.println("5.Register a student");
System.out.println("6.Back to Main Menu");
adminResponse = input.nextLine();
switch (adminResponse) {
//Create a Course
case "1":
admin.createCourse(allCourses, fullCourses);
break;
//Delete a Course
case "2":
//remove course from all university course list
admin.deleteCourse(allCourses, fullCourses);
break;
//Edit a Course
case "3":
admin.editCourse(allCourses, fullCourses);
break;
//Course Information by ID
case "4":
admin.getCourseInfoByID(allCourses);
break;
//Register a Student
case "5":
admin.registerStudent(allStudents);
break;
//EXIT
case "6":
System.out.println("--Back to Main Menu--");
//break while loop to return to Admin Menu
keepgoingManagement = false;
break;
}
}
break;
//REPORTS
case "2":
//loop to keep Reports Menu running
boolean keepgoingReportsMenu = true;
while (keepgoingReportsMenu == true) {
//REPORTS MENU
System.out.println("");
System.out.println("REPORTS");
System.out.println("");
System.out.println("1.View all courses");
System.out.println("2.View all courses that are FULL");
System.out.println("3.Write to a file the list of course that are full");
System.out.println("4.View the names of the students that are registered in a specific course");
System.out.println("5.View the list of courses that a given student is registered in");
System.out.println("6. Sort the courses based on the current number of students registered");
System.out.println("7. Back to Main Menu");
adminResponse = input.nextLine();
switch (adminResponse) {
//View All Courses
case "1":
admin.viewAllCourses(allCourses);
break;
//View All Full Courses
case "2":
admin.viewAllFullCourses(allCourses);
break;
//Write Full Course List to a File
case "3":
admin.downloadFullCourses(allCourses);
break;
//View Student List in a Course
case "4":
admin.viewStudentList(allCourses);
break;
//View Course List of a Student
case "5":
admin.viewStudentCourses(allStudents);
break;
//Sort Courses (based on registered student number)
case "6":
admin.sortCourses(allCourses);
break;
//EXIT
case "7":
System.out.println("--Back to Main Menu--");
keepgoingReportsMenu = false;
break;
}
}
break;
case "3":
System.out.println("--Exit--");
keepgoingAdminMenu = false;
break;
}
}
}
else if (response.toLowerCase().equals("student")) {
boolean keepgoing = true;
while (keepgoing == true) {
System.out.println("Please enter your login information:");
System.out.println("Username: ");
String username = input.nextLine();
System.out.println("Password: ");
String password = input.nextLine();
//for loop to check all student objects to see if user name and password matches
for (int i = 0; i < allStudents.size(); i++) {
Student stu = allStudents.get(i);
if (stu.getUsername().equals(username)) {
if (stu.getPassword().equals(password)) {
//assign loggedStudent to the student object if a match is found
loggedStudent = stu;
keepgoing = false; //exit loop
System.out.print("...Login Successful...");
break;
}
else {
System.out.println("Wrong username or password.");
keepgoing = true;
}
}
}
}
System.out.println("");
System.out.println("");
boolean keepgoingStudentMenu = true;
while (keepgoingStudentMenu == true) {
//Student Menu
System.out.println("Course Management");
System.out.println("");
System.out.println("1.View all courses");
System.out.println("2.View all open courses");
System.out.println("3.Register in a course");
System.out.println("4.Withdraw from a course");
System.out.println("5.View my courses");
System.out.println("6.Exit");
String studentResponse = input.nextLine();
switch (studentResponse) {
//View All Courses
case "1":
loggedStudent.viewAllCourses(allCourses);
break;
//View All Open Courses
case "2":
loggedStudent.viewAllOpenCourses(allCourses);
break;
//Register to a Course
case "3":
loggedStudent.registerToCourse(allCourses, allStudents);
break;
//Withdraw from a Course
case "4":
loggedStudent.withdrawFromCourse(allCourses);
break;
//View My Courses
case "5":
loggedStudent.viewMyCourses();
break;
//EXIT
case "6":
System.out.println("--Exit--");
keepgoingStudentMenu = false; //exit loop
break;
}
}
}
else {
System.out.println("You have to be an admin or a student to use this system.");
}
//SERIALIZATION
try{
FileOutputStream fos1= new FileOutputStream("All_Courses.ser");
ObjectOutputStream oos1= new ObjectOutputStream(fos1);
oos1.writeObject(allCourses);
oos1.close();
fos1.close();
}
catch(IOException ioe){
ioe.printStackTrace();
}
try {
FileOutputStream fos2= new FileOutputStream("All_Students.ser");
ObjectOutputStream oos2= new ObjectOutputStream(fos2);
oos2.writeObject(allStudents);
oos2.close();
fos2.close();
}
catch(IOException ioe){
ioe.printStackTrace();
}
input.close();
}
/**
* Reads and adds courses from CSV file to the Course Registration System
*/
public static void addCoursesToSystem() throws FileNotFoundException {
Scanner inputFile = new Scanner(new File("MyUniversityCourses.csv"));
inputFile.nextLine();
while(inputFile.hasNextLine()) {
String line = inputFile.nextLine();
String[] course = line.split(",");
ArrayList<Student> studentList = new ArrayList<Student>();
//assign each element of course array to appropriate data types
String courseName = course[0];
String courseId = course[1];
int maxStudents = Integer.parseInt(course[2]);
int currentStudents = Integer.parseInt(course[3]);
String courseInstructor = course[5];
int sectionNumber = Integer.parseInt(course[6]);
String courseLocation = course[7];
//create Course objects and add them to the allCourses array
allCourses.add(new Course(courseName, courseId, maxStudents, currentStudents, studentList, courseInstructor, sectionNumber, courseLocation, ""));
}
inputFile.close();
}
}