-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCourse.java
More file actions
206 lines (179 loc) · 5.58 KB
/
Copy pathCourse.java
File metadata and controls
206 lines (179 loc) · 5.58 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
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import java.util.Random;
/**
* Course class
* <p>
* A representation for one course that a certain number of students
* can access.
*
* @author Anushka Nilangekar
* @version December 11, 2021
*/
public class Course {
/**
* Title of the course
*/
private String name;
/**
* Teacher assigned to this course
*/
private Teacher courseTeacher;
/**
* Enrollment capacity of the course
*/
private int enrollmentCapacity;
/**
* students enrolled
*/
private ArrayList<Student> studentsInThisCourse;
/**
* QuizArchive with quizzes
*/
static QuizArchive quizArchive = new QuizArchive();
/**
* all quizzes
*/
ArrayList<Quiz> quizzes;
/**
* get students
*/
public ArrayList<Student> getStudentsInThisCourse() {
return this.studentsInThisCourse;
}
public void assignStudentUsernames() {
var students = Student.students;
for (int i = 0; i < students.size(); i++) {
for (int j = 0; j < studentsInThisCourse.size(); j++) {
if (students.get(i).getName().equals(studentsInThisCourse.get(j).getName())) {
studentsInThisCourse.get(j).setUsername(students.get(i).getUsername());
}
}
}
}
/**
* sets students
*
* @param studentsInThisCourse = students to be set
*/
public void setStudentsInThisCourse(ArrayList<Student> studentsInThisCourse) {
this.studentsInThisCourse = studentsInThisCourse;
}
/**
* Allocates a new course object with its title, assigned teacher and enrollment count.
*
* @param name = course title.
* @param enrollmentCapacity = Enrollment capacity of the course
* @param teacher = teacher to be assigned
* @throws InvalidCourseException = throws an exception when there is 0 enrollment capacity for the course.
*/
public Course(String name, Teacher teacher, int enrollmentCapacity) throws InvalidCourseException,
FileNotFoundException {
this.name = name;
this.courseTeacher = teacher;
this.enrollmentCapacity = enrollmentCapacity;
studentsInThisCourse = new ArrayList<>();
quizzes = new ArrayList<>();
if (enrollmentCapacity < 1)
throw new InvalidCourseException("A course should have a minimum student enrollment of 1!");
}
/**
* Allocates a new course object with its title, assigned teacher and enrollment count.
*
* @param name = course title.
* @param enrollmentCapacity = Enrollment capacity of the course
* @param teacher = teacher to be assigned
* @param studentsInThisCourse = students to be added for the course
* @throws InvalidCourseException = throws an exception when there is 0 enrollment capacity for the course.
*/
public Course(String name, Teacher teacher, int enrollmentCapacity, ArrayList<Student> studentsInThisCourse)
throws InvalidCourseException, FileNotFoundException {
this(name, teacher, enrollmentCapacity);
this.studentsInThisCourse = studentsInThisCourse;
if (enrollmentCapacity < 1)
throw new InvalidCourseException("A course should have a minimum student enrollment capacity of 1!");
quizzes = new ArrayList<>();
}
public ArrayList<Quiz> getQuizzes() {
return quizzes;
}
public void addCourseQuiz(Quiz quiz) {
quizzes.add(quiz);
}
/**
* adds a student
*
* @param student = student to be added
*/
public void addAStudentToTheCourse(Student student) {
studentsInThisCourse.add(student);
}
/**
* get name
*
* @return name
*/
public String getName() {
return this.name;
}
/**
* get courseTeacher
*
* @return courseTeacher
*/
public Teacher getCourseTeacher() {
return this.courseTeacher;
}
/**
* get enrollmentCapacity
*
* @return enrollmentCapacity
*/
public int getEnrollmentCapacity() {
return this.enrollmentCapacity;
}
/**
* sets courseTeacher
*
* @param newCourseTeacher = new teacher
*/
public void setCourseTeacher(Teacher newCourseTeacher) {
this.courseTeacher = newCourseTeacher;
}
/**
* sets enrollmentCapacity
*
* @param newEnrollmentCapacity = new enrollmentCapacity
*/
public void setEnrollmentCapacity(int newEnrollmentCapacity) {
this.enrollmentCapacity = newEnrollmentCapacity;
}
/**
* sets name
*
* @param newName = new name
*/
public void setName(String newName) {
this.name = newName;
}
/**
* get quizArchive
*
* @return quizArchive
*/
public static QuizArchive getQuizArchive() {
return quizArchive;
}
/**
* calls the quiz menu
*
* @throws InvalidQuizException = thrown when appropriate
* @throws FileNotFoundException = thrown when appropriate
*/
public void callTheQuizFunction(String courseTitle) throws InvalidQuizException, IOException {
quizArchive = Application.quizArchive;
TheQuizFunction.main(quizArchive, courseTitle);
}
}