-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.java
More file actions
140 lines (124 loc) · 4 KB
/
Program.java
File metadata and controls
140 lines (124 loc) · 4 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
package data;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class Program {
private final String programName;
private final String programID;
private final ArrayList<Bloc> blocs;
public Program(String programName, String programID) {
this.programName = programName;
this.programID = programID;
this.blocs = new ArrayList<>();
}
public void addBloc(Bloc bloc) {
blocs.add(bloc);
}
public String getProgramName() {
return programName;
}
public String getProgramID() {
return programID;
}
public ArrayList<Bloc> getBlocs() {
return blocs;
}
public ArrayList<Course> getCourse() {
ArrayList<Course> listCourse = new ArrayList<>();
for (Bloc bloc : blocs) {
listCourse.addAll(bloc.getBlocCourses());
}
return listCourse;
}
public double getMoyenne(Student student) {
double moyenne = 0;
for(Bloc bloc : blocs) {
double temp = bloc.getMoyenne(student);
if(temp >= 0) {
moyenne += temp;
}
}
return moyenne / blocs.size();
}
public double getNoteMoyenne(List<Student> studentList) {
int nbNotes = 0;
double sommeNotes = 0;
for(Student student : studentList) {
if(student.getProgram().getProgramID().equals(this.getProgramID())) {
double note = this.getMoyenne(student);
if (note != -1) {
sommeNotes += note;
nbNotes += 1;
}
}
}
return sommeNotes / nbNotes;
}
/*duplication de code , cherher une méthode pour remédier à ce problème*/
public double getNoteMax(List<Student> studentList) {
double max = 0;
for (int i = 0, studentListSize = studentList.size(); i < studentListSize; i++) {
Student student = studentList.get(i);
if (student.getProgram().getProgramID().equals(this.getProgramID())) {
double moyenne = this.getMoyenne(student);
if (moyenne > max && moyenne >= 0) {
max = moyenne;
}
}
}
return max;
}
public double getNoteMin(List<Student> studentList) {
double min = 20;
for(Student student : studentList) {
if(student.getProgram().getProgramID().equals(this.getProgramID())) {
double moyenne = this.getMoyenne(student);
if (moyenne < min && moyenne >= 0) {
min = moyenne;
}
}
}
return min;
}
public double getEcartType(List<Student> studentList) {
List<Double> listNote = new ArrayList<>();
double moyenne = this.getNoteMoyenne(studentList);
for(Student student : studentList) {
if(student.getProgram().getProgramID().equals(this.getProgramID())) {
double moyenneStudent = this.getMoyenne(student);
if (moyenneStudent >= 0) {
listNote.add(moyenneStudent);
}
}
}
double acc = 0;
for (Double note : listNote)
{
if(note >= 0) {
double squrDiffToMean = Math.pow(note - moyenne, 2);
acc += squrDiffToMean;
}
}
double meanOfDiffs = acc / listNote.size();
return Math.sqrt(meanOfDiffs);
}
@Override
public boolean equals(Object obj) {
boolean areEqual = false;
if (obj instanceof Program) {
areEqual = Objects.equals(this.programID,this.programName);
}
return areEqual;
}
@Override
public int hashCode() {
return Objects.hash(this.programID,this.programName);
}
@Override
public String toString() {
return programID + " " + programName +
"\n" +
blocs.toString() +
"\n";
}
}