From d047ec6156215732d4efe5c5508477a8a1103fd1 Mon Sep 17 00:00:00 2001 From: MSAYIF Bassem <bassem.msayif@etu.univ-amu.fr> Date: Sat, 12 Sep 2020 20:10:15 +0200 Subject: [PATCH] Updated Student Class + Added TestStudent Class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implémentation des méthodes addResult, getGrades, toString, averageGrade, printTesults dans la classe Student. - Creation d'une classe TestStudent permettant de s'assurer du bon fonctionnement des méthodes implémentées dans la classe Student. --- tp1/Student.java | 15 +++++++++++++++ tp1/TestStudent.java | 46 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tp1/TestStudent.java diff --git a/tp1/Student.java b/tp1/Student.java index 9898a66..262330f 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 0000000..3b752af --- /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(); + } + + +} -- GitLab