-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCourseArchive.java
More file actions
94 lines (79 loc) · 2.36 KB
/
Copy pathCourseArchive.java
File metadata and controls
94 lines (79 loc) · 2.36 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
import java.io.FileNotFoundException;
import java.util.ArrayList;
/**
* CourseArchive
* <p>
* saves all courses
*
* @author Anushka, Anish Ketha, Zuhair
* @version December 11, 2021
*/
public class CourseArchive {
/**
* all courses
*/
public ArrayList<Course> courses;
/**
* courses that are read
*/
public ArrayList<Course> coursesAfterReading;
/*
* all courses (static)
*/
public static ArrayList<Course> allCourses = new ArrayList<>();
/**
* sync threads
*/
private static Object sync = new Object();
/**
* contructs courses
*
* @throws InvalidCourseException = thrown when appropriate
*/
public CourseArchive() throws InvalidCourseException {
coursesAfterReading = new ArrayList<>();
courses = new ArrayList<>();
//Teacher.readAllCourses();
if (coursesAfterReading != null) {
courses = coursesAfterReading;
} else {
courses = new ArrayList<>();
}
}
/**
* contructs courses
*
* @param course = to be added
* @throws InvalidCourseException = thrown when appropriate
*/
public CourseArchive(Course course) throws InvalidCourseException, FileNotFoundException {
this();
courses.add(course);
allCourses.add(course);
}
//adds a course to the courseArchive
public void addCourses(Course course) throws FileNotFoundException {
allCourses.add(course);
Teacher.writeCourses(allCourses);
}
public static void addStaticCourses(Course course) throws FileNotFoundException {
synchronized (sync) {
allCourses.add(course);
Teacher.writeCourses(allCourses);
}
}
//method that allows teacher to see all the courses
public ArrayList<Course> getCourses() {
return allCourses;
}
//method which allows a teacher to delete an unwanted course
public void deleteACourse(String titleOfTheCourse) throws FileNotFoundException {
for (int i = 0; i < allCourses.size(); i++) {
if (allCourses.get(i).getName().equals(titleOfTheCourse)) {
allCourses.remove(i);
break;
}
}
Teacher.writeCourses(allCourses);
}
}