diff --git a/tp1/Cohort.java b/tp1/Cohort.java index e199e790e8c0dad4a95033147e150e6a0a1a8fd6..49e6bc2a6f4d93276217f90091a538db1d077fca 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 262330fa0172295a73a9ea8c7c81e9af33b0c53b..36269a313c4d2d187636c3bc80bfd2f6bf7fa75f 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 0000000000000000000000000000000000000000..c404ea6901618e0e3fdc2bc9a786805cd056a0ce --- /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 a14026ca01edcbfb3ed9937660ab184f11faa41f..d8d787b172990706016f66437ea8d310fc8cfbbc 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()))