-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.java
More file actions
123 lines (107 loc) · 3.44 KB
/
Course.java
File metadata and controls
123 lines (107 loc) · 3.44 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
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class Course {
//variables:
private String name;
private Teacher teacher;
private int unitsOfTheCourse;
private List<Student> students;
private boolean isActive;
private List<Assignment> assignments;
private Date examTime;
private int studentsCount;
public FileWriter infoWriter;
public FileWriter studentsWriter;
//constractors:
public Course(String name) throws IOException {
this.name = name;
this.students = new ArrayList<>();
this.assignments = new ArrayList<>();
this.infoWriter = new FileWriter("D:\\University\\AP\\project\\project files\\courses\\courseInformations\\"
+ name + "_info.txt", true);
this.studentsWriter = new FileWriter("D:\\University\\AP\\project\\project files\\courses\\courseStudents\\"
+ name + "_students.txt", true);
}
public Course(String name, Teacher teacher, int unitsOfTheCourse){
this.name = name;
this.teacher = teacher;
this.unitsOfTheCourse = unitsOfTheCourse;
this.isActive = true;
this.studentsCount = 0;
this.students = new ArrayList<>();
this.assignments = new ArrayList<>();
}
//getters:
public String getName() {
return name;
}
public Teacher getTeacher() {
return teacher;
}
public int getUnitsOfTheCourse() {
return unitsOfTheCourse;
}
public List<Student> getStudents() {
return students;
}
public List<Assignment> getAssignments() {
return assignments;
}
public Date getExamTime() {
return examTime;
}
//setters:
public void setTeacher(Teacher teacher) {
this.teacher = teacher;
try {
infoWriter.write("Teacher ID: " + teacher.getId() + "\n");
infoWriter.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
public void setUnitsOfTheCourse(int unitsOfTheCourse) {
this.unitsOfTheCourse = unitsOfTheCourse;
}
public void setActive(boolean active) {
isActive = active;
}
public void setAssignments(List<Assignment> assignments) {
this.assignments = assignments;
}
public void setExamTime(Date examTime) {
this.examTime = examTime;
}
public void setStudents(List<Student> students) {
this.students = students;
}
public void setStudentsCount(int studentsCount) {
this.studentsCount = studentsCount;
}
//methods:
public void printStudents() {
System.out.println("This students are in the course: ");
for (Student student : students) {
System.out.println(student.getId());
}
}
public void addStudent(Student student) {
students.add(student);
}
public void removeStudent(Student student) {
students.remove(student);
}
public Student findTopScorer() {
Student topScorer = null;
double highestGrade = 0;
for (Student student : students) {
double grade = student.getThisCourseTotalAverage();
if (grade > highestGrade) {
highestGrade = grade;
topScorer = student;
}
}
return topScorer;
}
}