-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentInterface.java
228 lines (219 loc) · 11 KB
/
StudentInterface.java
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
import java.io.Console;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* This is the UI/UX for the student menu
* there is check for invalid entries
* @author Team Stars
* @version 1.0
* @since 2020
*/
public class StudentInterface {
/**
* CourseManager for filtering list of course
*/
CourseManager courseMgmt = new CourseManager();
/**
* StudentManager for filtering list of student
*/
StudentManager studentMgmt = new StudentManager();
private List<Student> students;
private List<Course> courses;
private WaitList waitlist;
/**
* Constructor for student interface
* @param fullStudentList2 as the list of student
* @param coursesInput as the list of course
* @param waitListInput as the wait list
*/
public StudentInterface(List<Student> fullStudentList2,List<Course>coursesInput,WaitList waitListInput) {
this.students = fullStudentList2;
this.courses = coursesInput;
this.waitlist = waitListInput;
}
/**
* this funtions is to print the main menu and checks all the valid entries
* handling the calling of object functions
* @param currentStudent is an student object from login
* @param db is the database class to load all student and course
* @throws IOException is the trace for database reading exception
*/
public void StudentMenuLogic(Student currentStudent, Database db) throws IOException {
String num = "", courseIndex = "", matricNo;
Console console = System.console();
System.out.println("Welcome to Student Mode");
Boolean quit = false;
Scanner sc = new Scanner(System.in);
// Initialize common variable/objets
int courseVacancy;
db.PrepopulateStudentCourses(students, courses,studentMgmt,waitlist);
Course currentCourse = new Course();
int intCheck;
while (!quit) {
System.out.println(
" 1 *Add Course \n 2 Drop Course \n 3 Check/Print Courses Registered \n 4 Check Vacancies Available \n 5 Change Index Number of Course \n 6 Swop Index Number with Another Student \n 7 Printing all available courses \n 8 Check Waiting List \n 9 Print Current Timetable \n 10 Quit");
num = console.readLine("Please choose your action \n");
switch (num) {
case "1":
System.out.println("\nEnter a course index");
// assuming course index is unique
courseIndex = sc.next();
currentCourse = studentMgmt.GetCourse(Integer.parseInt(courseIndex), courses);
if (currentCourse != null) {
studentMgmt.AddCourse(currentCourse, waitlist, currentStudent);
} else {
System.out.println(("Please enter an exisiting course index :"));
courseMgmt.AvailableCourse.Display(courses);
}
System.out.println("\n ----");
break;
case "2":
System.out.println("\nRemove a course");
System.out.println("\nEnter a course index");
courseIndex = sc.next();
try {
intCheck = Integer.parseInt(courseIndex);
} catch (NumberFormatException ex) {
System.out.println("invalid input, must enter a valid course index number(Integer)");
break;
}
// find corresponding course object using these course code & index
currentCourse = studentMgmt.GetCourse(Integer.parseInt(courseIndex), courses);
if (currentCourse == null) {
System.out.println("No courses found");
// sc.nextLine();
break;
}
studentMgmt.RemoveCourse(currentCourse, waitlist, currentStudent);
break;
case "3":
System.out.println("\nCheck/Print Courses Registered");
ArrayList<Course> studentCourse = currentStudent.getCourse();
if (studentCourse == null) {
System.out.println("No courses found");
break;
}
studentMgmt.printAllCourse(studentCourse);
break;
case "4":
System.out.println("\nCheck Vacancies Available");
System.out.println("\nEnter a course index");
courseIndex = sc.next();
try {
intCheck = Integer.parseInt(courseIndex);
} catch (NumberFormatException ex) {
System.out.println("invalid input, must enter a valid course index number(Integer)");
break;
}
currentCourse = studentMgmt.GetCourse(Integer.parseInt(courseIndex), courses);
courseVacancy = currentCourse.getVacancy();
System.out.println("Course Vacancy for " + courseIndex + " is " + courseVacancy);
break;
case "5":
System.out.println("\nChange Index Number of Course");
System.out.println("\nEnter current course index");
courseIndex = sc.next();
try {
intCheck = Integer.parseInt(courseIndex);
} catch (NumberFormatException ex) {
System.out.println("invalid input, must enter a valid course index number(Integer)");
break;
}
System.out.println("\nEnter a course index that you want to change to");
String changeIndex = sc.next();
try {
intCheck = Integer.parseInt(changeIndex);
} catch (NumberFormatException ex) {
System.out.println("invalid input, must enter a valid 2nd course index number(Integer)");
break;
}
currentCourse = studentMgmt.GetCourse(Integer.parseInt(courseIndex), courses);
if (currentCourse == null) {
System.out.println("Course not found");
break;
}
System.out.println("\nInformation for Index" + courseIndex);
studentMgmt.printLessonInformation(Integer.parseInt(changeIndex));
System.out.println("\nInformation for Index" + changeIndex);
studentMgmt.printLessonInformation(Integer.parseInt(changeIndex));
System.out.println("\nConfirm Swap? Will remove current course and try to add new course Y / N");
String confirmation = sc.next();
if (confirmation.toUpperCase().equals("Y")) {
Course newCourse = studentMgmt.GetCourse(Integer.parseInt(changeIndex), courses);
studentMgmt.RemoveCourse(currentCourse, waitlist, currentStudent);
System.out.println("removed course "+currentCourse);
System.out.println("Try to add course "+newCourse);
studentMgmt.AddCourse(newCourse, waitlist, currentStudent);
}
break;
case "6":
String username ="";
String password ="";
String peerCourseIndex ="";
System.out.println("\nSwop Index Number with Another Student");
System.out.println("\nEnter other student's username");
username = sc.next();
System.out.println("\nEnter other student's password");
password = sc.next();
// get other student's corresponding object
System.out.println("\nEnter your current course index");
courseIndex = sc.next();
try {
intCheck = Integer.parseInt(courseIndex);
} catch (NumberFormatException ex) {
System.out.println("invalid input, must enter a valid course index number(Integer)");
break;
}
System.out.println("\nEnter peer's course index");
peerCourseIndex = sc.next();
try {
intCheck = Integer.parseInt(peerCourseIndex);
} catch (NumberFormatException ex) {
System.out.println("invalid input, must enter a valid course index number(Integer)");
break;
}
Student secondStudent = studentMgmt.GetStudentByUserName(username, students);
if(secondStudent== null)
{
System.out.println("\nWrong Username / 2nd student does not exist");
break;
}
currentCourse = studentMgmt.GetCourse(Integer.parseInt(courseIndex), courses);
studentMgmt.SwapCourse(currentStudent, secondStudent, currentCourse, Integer.parseInt(peerCourseIndex),password);
break;
case "7":
System.out.println("\nPrinting all available courses");
courseMgmt.AvailableCourse.Display(courses);
break;
case "8":
System.out.println("\nEnter Index: ");
String index = sc.next();
try {
intCheck = Integer.parseInt(index);
} catch (NumberFormatException ex) {
System.out.println("invalid input, must enter a valid index number(Integer)");
break;
}
System.out.println("\nDisplay Waiting List for Index: " + index);
List<Course> currentList = courseMgmt.byIndex.Invoke(courses, index);
courseMgmt.currentIndexWaitingList.Display(currentList);
break;
case "9":
System.out.println("Printing Current Time Table");
studentMgmt.GenerateTimeTable(currentStudent.getCourse());
break;
case "10":
System.out.println("\nQuit");
db.UpdateCourseDatabase(courses);
db.UpdateStudentDatabase(students);
sc.close();
quit = true;
System.exit(1);
break;
default:
}
}
}
}