Skip to content
Snippets Groups Projects
Commit bb14bf0b authored by MSAYIF Bassem's avatar MSAYIF Bassem
Browse files

Tâches optionnelles finies

Ajouts des fonctionnalités suivantes:
- Ajout d'une méthode comptant le nombre d'étudiants ayant validé leur année (moyenne supérieure ou
égale à 10) dans une promotion.
- Changement de la classe Grade pour qu'elle permette de stocker des notes correspondant à une absence
du résultat (affiché ABS).
- Calcul du nombre d'absents d'une promotion.
- Calcul de la note maximum et minimum (hors absence) d'une promotion.
- Calcul pondéré de la moyenne de résultats en fonction du nombre de crédits des UE.
- Calcul de la moyenne (hors absence) d'une promotion.
parent add536f1
No related branches found
No related tags found
No related merge requests found
......@@ -44,6 +44,11 @@ public class Cohort {
for (Student student : students){
student.printResults();
}
System.out.println("Le nombre d'étudiants ayant validé leur année : " + getPass());
System.out.println("L'étudiant avec la note la plus élevée : " + maxAverageName() + " avec une moyenne de " + maxAverage() + "/20");
System.out.println("L'étudiant avec la note la plus basse : " + minAverageName() + " avec une moyenne de " + minAverage() + "/20");
System.out.println("La moyenne de la classe est de : " + getAverageOfClass());
}
private void printName(){
......@@ -58,4 +63,64 @@ public class Cohort {
public String toString() {
return this.name;
}
public int getPass(){
int pass = 0;
for (Student student : students){
if (student.getAverageGrade().getValue() >= 10){
pass += 1;
}
}
return pass;
}
public double maxAverage(){
double max = 0;
for (Student student : students){
if (student.getAverageGrade().getValue() > max){
max = student.getAverageGrade().getValue();
}
}
return max;
}
public String maxAverageName(){
double max = 0;
String name = "";
for (Student student : students){
if (student.getAverageGrade().getValue() > max){
max = student.getAverageGrade().getValue();
name = student.toString();
}
}
return name;
}
public double minAverage(){
double min = 21;
for (Student student : students){
if (student.getAverageGrade().getValue() < min){
min = student.getAverageGrade().getValue();
}
}
return min;
}
public String minAverageName(){
double min = 21;
String name = "";
for (Student student : students){
if (student.getAverageGrade().getValue() < min){
min = student.getAverageGrade().getValue();
name = student.toString();
}
}
return name;
}
public double getAverageOfClass(){
int number = 0;
double sum = 0;
double avg;
for (Student student : students){
number += 1;
sum += student.getAverageGrade().getValue();
}
avg = sum / number;
return avg;
}
}
......@@ -10,6 +10,7 @@ public class Grade {
*/
private static final int MAXIMUM_GRADE = 20;
private final double value;
private boolean ABS = false;
/**
* Constructs a grade with a value equals to the specified {@code value}.
......@@ -21,6 +22,25 @@ public class Grade {
this.value = value;
}
public void setABS(){
this.ABS = true;
}
public boolean isABS(){
return this.ABS;
}
public static int amountABS(List<Grade> grades){
int total = 0;
for (Grade grade : grades){
if (grade.isABS()){
total += 1;
}
}
return total;
}
/**
* Returns the value of the grade as a double.
*
......
......@@ -2,10 +2,10 @@ public class Main {
public static void main(String[] args){
Student bassem = new Student("Bassem", "MSAYIF");
Student haiDang = new Student("Hai Dang", "LE");
bassem.addResult("Programmation 2", new Grade(20));
bassem.addResult("Structures discrètes", new Grade(20));
haiDang.addResult("Programmation 2", new Grade(10));
haiDang.addResult("Structures discrètes", new Grade(9.75));
bassem.addResult("Programmation 2", new Grade(20), 6);
bassem.addResult("Structures discrètes", new Grade(20), 6);
haiDang.addResult("Programmation 2", new Grade(14), 6);
haiDang.addResult("Structures discrètes", new Grade(13), 6);
Cohort l2 = new Cohort("L2 Informatique");
l2.addStudent(bassem);
l2.addStudent(haiDang);
......
......@@ -30,8 +30,8 @@ public class Student {
* @param teachingUnitName the name of the teaching unit of the added result
* @param grade the grade of the added result
*/
public void addResult(String teachingUnitName, Grade grade){
results.add(new TeachingUnitResult(teachingUnitName, grade));
public void addResult(String teachingUnitName, Grade grade, int credit){
results.add(new TeachingUnitResult(teachingUnitName, grade, credit));
}
/**
......@@ -52,8 +52,10 @@ public class Student {
public List<Grade> getGrades(){
List<Grade> grades = new ArrayList<Grade>();
for (TeachingUnitResult result : results){
for(int coef = 0 ; coef < result.getCredits() ; coef += 1) {
grades.add(result.getGrade());
}
}
return grades;
}
......
......@@ -5,6 +5,7 @@
public class TeachingUnitResult {
private final String teachingUnitName;
private final Grade grade;
private int credits = 1;
/**
......@@ -15,9 +16,14 @@ public class TeachingUnitResult {
* @param grade the grade of the constructed TeachingUnitResult
*/
public TeachingUnitResult(String teachingUnitName, Grade grade) {
public TeachingUnitResult(String teachingUnitName, Grade grade, int credits) {
this.teachingUnitName = teachingUnitName;
this.grade = grade;
this.credits = credits;
}
public int getCredits(){
return this.credits;
}
/**
......
......@@ -40,12 +40,12 @@ public class TestCohort {
public void testPrintStudentResults(){
Student student1 = new Student("Pierre","LE BOULANGER");
student1.addResult("Programmation 2",new Grade(10));
student1.addResult("Structures discrètes",new Grade(20));
student1.addResult("Programmation 2",new Grade(10), 1);
student1.addResult("Structures discrètes",new Grade(20), 1);
Student student2 = new Student("Raphael","LE PATISSIER");
student2.addResult("Programmation 2",new Grade(10));
student2.addResult("Structures discrètes",new Grade(0));
student2.addResult("Programmation 2",new Grade(10), 1);
student2.addResult("Structures discrètes",new Grade(0), 1);
Cohort cohortTest = new Cohort("Informatique L2 \n");
cohortTest.addStudent(student1);
......
......@@ -25,7 +25,7 @@ public class TestStudent {
grades.add(new Grade(15));
grades.add(new Grade(10));
for (Grade grade : grades){
student2.addResult("teachingUnit", grade);
student2.addResult("teachingUnit", grade, 1);
}
return (grades.equals(student2.getGrades()));
}
......@@ -37,8 +37,8 @@ public class TestStudent {
public void testPrintResults(){
Student student1 = new Student("Arnaud", "Labourel");
student1.addResult("Programmation 2",new Grade(20));
student1.addResult("Structures discrètes",new Grade(20));
student1.addResult("Programmation 2",new Grade(20), 1);
student1.addResult("Structures discrètes",new Grade(20), 1);
student1.printResults();
}
......
......@@ -16,7 +16,7 @@ public class TestTeachingUnitResult {
public boolean testToString(){
TeachingUnitResult teachingUnitResult = new TeachingUnitResult("programmation2", new Grade(0));
TeachingUnitResult teachingUnitResult = new TeachingUnitResult("programmation2", new Grade(0), 1);
String teachingUnitResultString = teachingUnitResult.toString();
if(teachingUnitResultString == "programmation2"){
return true;
......@@ -25,8 +25,8 @@ public class TestTeachingUnitResult {
}
public boolean testEquals(){
TeachingUnitResult teachingUnitResult = new TeachingUnitResult("",new Grade(15));
TeachingUnitResult teachingUnitResult1 = new TeachingUnitResult( "", new Grade(15));
TeachingUnitResult teachingUnitResult = new TeachingUnitResult("",new Grade(15), 1);
TeachingUnitResult teachingUnitResult1 = new TeachingUnitResult( "", new Grade(15), 1);
if(teachingUnitResult.equals(teachingUnitResult1.getGrade()))
{
return true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment