diff --git a/tp1/Student.java b/tp1/Student.java index 9898a666f45ccd49189150bba98d8aa44f45912e..262330fa0172295a73a9ea8c7c81e9af33b0c53b 100644 --- a/tp1/Student.java +++ b/tp1/Student.java @@ -31,6 +31,7 @@ public class Student { * @param grade the grade of the added result */ public void addResult(String teachingUnitName, Grade grade){ + results.add(new TeachingUnitResult(teachingUnitName, grade)); } /** @@ -39,6 +40,7 @@ public class Student { */ @Override public String toString() { + return firstName + " " + lastName; } @@ -48,6 +50,11 @@ public class Student { * @return the grades of the student */ public List<Grade> getGrades(){ + List<Grade> grades = new ArrayList<Grade>(); + for (TeachingUnitResult result : results){ + grades.add(result.getGrade()); + } + return grades; } /** @@ -56,6 +63,7 @@ public class Student { * @return the average grade of the student */ public Grade getAverageGrade() { + return Grade.averageGrade(getGrades()); } @Override @@ -81,12 +89,19 @@ public class Student { * the average grade of the student. */ public void printResults(){ + this.printName(); + for (TeachingUnitResult result : results){ + System.out.println(result + " : " + result.getGrade() + "\n"); + } + this.printAverageGrade(); } private void printName() { + System.out.println(toString() + "\n"); } private void printAverageGrade() { + System.out.println("Note moyenne : " + getAverageGrade()); } } diff --git a/tp1/TestStudent.java b/tp1/TestStudent.java new file mode 100644 index 0000000000000000000000000000000000000000..3b752af68180d91fcad9ba8bd2a5f8c2aede9e4c --- /dev/null +++ b/tp1/TestStudent.java @@ -0,0 +1,46 @@ +import java.util.ArrayList; +import java.util.List; + +public class TestStudent { + public static void main(String[] args){ + TestStudent test = new TestStudent(); + if(test.testGrade() == true) + System.out.println("TestStudentValue : correct"); + else + System.out.println("TestStudentValue : incorrect"); + + if(test.testToString() == true) + System.out.println("testToString : correct"); + else + System.out.println("testToString : incorrect"); + + test.testPrintResults(); + + } + + public boolean testGrade(){ + Student student2 = new Student("Prénom", "Nom"); + List<Grade> grades = new ArrayList<Grade>(); + grades.add(new Grade(20)); + grades.add(new Grade(15)); + grades.add(new Grade(10)); + for (Grade grade : grades){ + student2.addResult("teachingUnit", grade); + } + return (grades.equals(student2.getGrades())); + } + + public boolean testToString(){ + Student student3 = new Student("Prénom", "Nom"); + return (student3.toString().equals("Prénom Nom")); + } + + 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.printResults(); + } + + +}