Skip to content
Snippets Groups Projects
Commit 8e5f81f5 authored by Hai Dang's avatar Hai Dang
Browse files

Updated Cohort, Student, TestCohort, TestTeachingUnitResult.

Implementation des méthodes addStudent,getStudent, toString,
printStudentResults dans la class Cohort, ajout de la class TestCohort,
modification de la class TestTeachingUnitResult, et mis a jour du format
d'affichage de la class Student
parent d047ec61
Branches
No related tags found
No related merge requests found
......@@ -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;
}
}
......@@ -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");
}
}
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();
}
}
......@@ -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()))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment