-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubject.java
More file actions
40 lines (35 loc) · 1.44 KB
/
Subject.java
File metadata and controls
40 lines (35 loc) · 1.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
import java.util.ArrayList;
public class Subject extends Discipline {
private ArrayList<Theme> themes;
public Subject(String title, ArrayList<Theme> themes) {
super(title);
this.themes = themes;
UpdateGrade();
UpdateEquivalentRating();
}
public void UpdateGrade() {
double currentGradeSum = 0;
double maxGradeSum = 0;
for (var theme : themes) {
currentGradeSum += theme.getCurrentOnlineLessonsGrade();
maxGradeSum += theme.getMaxOnlineLessonsGrade();
}
currentOnlineLessonsGrade = currentGradeSum;
maxOnlineLessonsGrade = maxGradeSum;
}
public ArrayList<Theme> getThemes() {
return themes;
}
@Override
public String toString() {
UpdateGrade();
UpdateEquivalentRating();
var chaptersStringFormat = "";
for (int i = 0; i < getThemes().stream().count(); i++) {
chaptersStringFormat += getThemes().get(i).toString();
if (i < getThemes().stream().count() - 1) chaptersStringFormat += "\n";
}
return new String(" " + getTitle() + " (" + String.valueOf(getCurrentOnlineLessonsGrade()) + " / " + String.valueOf(getMaxOnlineLessonsGrade()) +") "
+ getEquivalentRating() + ":" + "\n" + (!getThemes().isEmpty() ? chaptersStringFormat : " В данном предмете нет глав"));
}
}