From bb14bf0b7b041c3e4ebd334c5005f6d2e9ce1679 Mon Sep 17 00:00:00 2001 From: MSAYIF Bassem <bassem.msayif@etu.univ-amu.fr> Date: Sun, 13 Sep 2020 00:48:20 +0200 Subject: [PATCH] =?UTF-8?q?T=C3=A2ches=20optionnelles=20finies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tp1/Cohort.java | 65 +++++++++++++++++++++++++++++++++ tp1/Grade.java | 20 ++++++++++ tp1/Main.java | 8 ++-- tp1/Student.java | 8 ++-- tp1/TeachingUnitResult.java | 8 +++- tp1/TestCohort.java | 8 ++-- tp1/TestStudent.java | 6 +-- tp1/TestTeachingUnitResult.java | 6 +-- 8 files changed, 111 insertions(+), 18 deletions(-) diff --git a/tp1/Cohort.java b/tp1/Cohort.java index 49e6bc2..1cfb9d9 100644 --- a/tp1/Cohort.java +++ b/tp1/Cohort.java @@ -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; + } } diff --git a/tp1/Grade.java b/tp1/Grade.java index b4161d8..b6a491f 100644 --- a/tp1/Grade.java +++ b/tp1/Grade.java @@ -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. * diff --git a/tp1/Main.java b/tp1/Main.java index c09d3d7..f5947c2 100644 --- a/tp1/Main.java +++ b/tp1/Main.java @@ -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); diff --git a/tp1/Student.java b/tp1/Student.java index 36269a3..56e654c 100644 --- a/tp1/Student.java +++ b/tp1/Student.java @@ -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,7 +52,9 @@ public class Student { public List<Grade> getGrades(){ List<Grade> grades = new ArrayList<Grade>(); for (TeachingUnitResult result : results){ - grades.add(result.getGrade()); + for(int coef = 0 ; coef < result.getCredits() ; coef += 1) { + grades.add(result.getGrade()); + } } return grades; diff --git a/tp1/TeachingUnitResult.java b/tp1/TeachingUnitResult.java index ef76d75..743be06 100644 --- a/tp1/TeachingUnitResult.java +++ b/tp1/TeachingUnitResult.java @@ -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; } /** diff --git a/tp1/TestCohort.java b/tp1/TestCohort.java index c404ea6..60639f6 100644 --- a/tp1/TestCohort.java +++ b/tp1/TestCohort.java @@ -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); diff --git a/tp1/TestStudent.java b/tp1/TestStudent.java index 3b752af..3211e95 100644 --- a/tp1/TestStudent.java +++ b/tp1/TestStudent.java @@ -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(); } diff --git a/tp1/TestTeachingUnitResult.java b/tp1/TestTeachingUnitResult.java index d8d787b..c73fc4d 100644 --- a/tp1/TestTeachingUnitResult.java +++ b/tp1/TestTeachingUnitResult.java @@ -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; -- GitLab