From 8e5f81f5194b909a47cac0651bdbd264c1a84e49 Mon Sep 17 00:00:00 2001 From: Hai Dang <hai-dang.le@etu.univ-amu.fr> Date: Sat, 12 Sep 2020 21:59:26 +0200 Subject: [PATCH] =?UTF-8?q?Updated=20Cohort,=20Student,=20TestCohort,=20Te?= =?UTF-8?q?stTeachingUnitResult.=20Implementation=20des=20m=C3=A9thodes=20?= =?UTF-8?q?addStudent,getStudent,=20toString,=20printStudentResults=20dans?= =?UTF-8?q?=20la=20class=20Cohort,=20ajout=20de=20la=20class=20TestCohort,?= =?UTF-8?q?=20modification=20de=20la=20class=20TestTeachingUnitResult,=20e?= =?UTF-8?q?t=20mis=20a=20jour=20du=20format=20d'affichage=20de=20la=20clas?= =?UTF-8?q?s=20Student?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tp1/Cohort.java | 8 +++++ tp1/Student.java | 8 +++-- tp1/TestCohort.java | 57 +++++++++++++++++++++++++++++++++ tp1/TestTeachingUnitResult.java | 15 +++++---- 4 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 tp1/TestCohort.java diff --git a/tp1/Cohort.java b/tp1/Cohort.java index e199e79..49e6bc2 100644 --- a/tp1/Cohort.java +++ b/tp1/Cohort.java @@ -24,6 +24,7 @@ public class Cohort { * @param student the student to be added to the cohort */ public void addStudent(Student student){ + this.students.add(student); } /** @@ -31,6 +32,7 @@ public class Cohort { * @return the list of students of the cohort. */ public List<Student> getStudents(){ + return students; } /** @@ -38,9 +40,14 @@ public class Cohort { * grade. */ public void printStudentsResults(){ + printName(); + for (Student student : students){ + student.printResults(); + } } private void printName(){ + System.out.println(this.name); } /** @@ -49,5 +56,6 @@ public class Cohort { */ @Override public String toString() { + return this.name; } } diff --git a/tp1/Student.java b/tp1/Student.java index 262330f..36269a3 100644 --- a/tp1/Student.java +++ b/tp1/Student.java @@ -55,6 +55,7 @@ public class Student { grades.add(result.getGrade()); } return grades; + } /** @@ -91,17 +92,18 @@ public class Student { public void printResults(){ this.printName(); for (TeachingUnitResult result : results){ - System.out.println(result + " : " + result.getGrade() + "\n"); + System.out.println(result + " : " + result.getGrade()); } this.printAverageGrade(); + } private void printName() { - System.out.println(toString() + "\n"); + System.out.println(toString()); } private void printAverageGrade() { - System.out.println("Note moyenne : " + getAverageGrade()); + System.out.println("Note moyenne : " + getAverageGrade()+ "\n"); } } diff --git a/tp1/TestCohort.java b/tp1/TestCohort.java new file mode 100644 index 0000000..c404ea6 --- /dev/null +++ b/tp1/TestCohort.java @@ -0,0 +1,57 @@ +import java.util.List; + +public class TestCohort { + public static void main(String[] args){ + TestCohort test = new TestCohort(); + if(test.testGetStudents()){ + System.out.println("testGetStudent = correct\n"); + } + else System.out.println("testGetStudent = incorrect\n"); + + if(test.testAddStudent()){ + System.out.println("testAddStudent = correct\n"); + } + else System.out.println("testAddStudent = incorrect\n"); + + test.testPrintStudentResults(); + } + + public boolean testAddStudent(){ + Cohort cohortTest = new Cohort(""); + cohortTest.addStudent(new Student("","")); + if (cohortTest.getStudents().size() == 1){ + return true; + } + return false; + } + + public boolean testGetStudents(){ + Cohort cohortTest = new Cohort(""); + for (int i = 0; i < 5; i++) { + cohortTest.addStudent(new Student("","")); + } + + if (cohortTest.getStudents().size() == 5){ + return true; + } + return false; + + } + + 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)); + + Student student2 = new Student("Raphael","LE PATISSIER"); + student2.addResult("Programmation 2",new Grade(10)); + student2.addResult("Structures discrètes",new Grade(0)); + + Cohort cohortTest = new Cohort("Informatique L2 \n"); + cohortTest.addStudent(student1); + + cohortTest.addStudent(student2); + cohortTest.printStudentsResults(); + } + +} diff --git a/tp1/TestTeachingUnitResult.java b/tp1/TestTeachingUnitResult.java index a14026c..d8d787b 100644 --- a/tp1/TestTeachingUnitResult.java +++ b/tp1/TestTeachingUnitResult.java @@ -2,17 +2,20 @@ public class TestTeachingUnitResult { public static void main(String[] args) { TestTeachingUnitResult test = new TestTeachingUnitResult(); - if (test.TestToString()){ - System.out.println("ok"); + if (test.testToString()){ + System.out.println("testToString : correct"); } - System.out.println(test.TestEquals()); - + else System.out.println("testToString : incorrect"); + if(test.testEquals()){ + System.out.println("testEquals : correct"); + } + else System.out.println("testEquals ; incorrect"); } - public boolean TestToString(){ + public boolean testToString(){ TeachingUnitResult teachingUnitResult = new TeachingUnitResult("programmation2", new Grade(0)); String teachingUnitResultString = teachingUnitResult.toString(); if(teachingUnitResultString == "programmation2"){ @@ -21,7 +24,7 @@ public class TestTeachingUnitResult { return false; } - public boolean TestEquals(){ + public boolean testEquals(){ TeachingUnitResult teachingUnitResult = new TeachingUnitResult("",new Grade(15)); TeachingUnitResult teachingUnitResult1 = new TeachingUnitResult( "", new Grade(15)); if(teachingUnitResult.equals(teachingUnitResult1.getGrade())) -- GitLab