Skip to content
Snippets Groups Projects
Commit b76bcfb0 authored by RANGHEARD Leo's avatar RANGHEARD Leo
Browse files

Fin des classes Grade, TeachingUnitResult, Student, Cohort, ainsi que les...

Fin des classes Grade, TeachingUnitResult, Student, Cohort, ainsi que les classes TestGrade, TestTeachingUnitResult, et TestStudent.
parent e1d29c46
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ public class Cohort {
/**
* Constructs a cohort with a name equals to the specified {@code name} and no students.
*
* @param name the name of the constructed Cohort
*/
......@@ -21,16 +22,20 @@ public class Cohort {
/**
* Add the specified {@code student} to the students of the cohort.
*
* @param student the student to be added to the cohort
*/
public void addStudent(Student student) {
students.add(student);
}
/**
* Returns the list of students of the cohort.
*
* @return the list of students of the cohort.
*/
public List<Student> getStudents() {
return students;
}
/**
......@@ -38,16 +43,24 @@ public class Cohort {
* grade.
*/
public void printStudentsResults() {
printName();
for (Student student : students){
student.printResults();
}
}
private void printName() {
System.out.println(name);
}
/**
* Returns the name of the cohort.
*
* @return the name of the cohort
*/
@Override
public String toString() {
return name;
}
}
......@@ -28,7 +28,7 @@ public class Grade {
*/
public double getValue() {
return value;
return this.value;
}
/**
......@@ -48,6 +48,12 @@ public class Grade {
* @return a grade corresponding to the mean of grade in {@code grades}
*/
public static Grade averageGrade(List<Grade> grades){
double averageValue = 0;
for (Grade grade : grades) {
averageValue += grade.getValue();
}
averageValue = averageValue / grades.size();
return new Grade(averageValue);
}
/**
......
......@@ -31,6 +31,8 @@ public class Student {
* @param grade the grade of the added result
*/
public void addResult(String teachingUnitName, Grade grade){
TeachingUnitResult unitResult = new TeachingUnitResult(teachingUnitName, grade);
results.add(unitResult);
}
/**
......@@ -39,6 +41,7 @@ public class Student {
*/
@Override
public String toString() {
return firstName + lastName;
}
......@@ -48,6 +51,11 @@ public class Student {
* @return the grades of the student
*/
public List<Grade> getGrades(){
List<Grade> listOfGrades = new ArrayList<>();
for (TeachingUnitResult result : results) {
listOfGrades.add(result.getGrade());
}
return listOfGrades;
}
/**
......@@ -56,6 +64,12 @@ public class Student {
* @return the average grade of the student
*/
public Grade getAverageGrade() {
double averageGrade = 0;
for (Grade grade : this.getGrades()) {
averageGrade += grade.getValue();
}
averageGrade = averageGrade / this.getGrades().size();
return new Grade(averageGrade);
}
@Override
......@@ -81,12 +95,21 @@ public class Student {
* the average grade of the student.
*/
public void printResults(){
printName();
for (TeachingUnitResult teachingUnitResult : results) {
System.out.println(teachingUnitResult.toString());
}
printAverageGrade();
System.out.println();
}
private void printName() {
System.out.println(this.toString());
}
private void printAverageGrade() {
System.out.println(this.getAverageGrade().toString());
}
}
......@@ -26,6 +26,7 @@ public class TeachingUnitResult {
* @return the grade associated to the result
*/
public Grade getGrade() {
return grade;
}
/**
......@@ -34,5 +35,6 @@ public class TeachingUnitResult {
*/
@Override
public String toString() {
return this.teachingUnitName + " : " + grade.toString();
}
}
import java.util.ArrayList;
import java.util.List;
public class TestStudent {
public static void main (String[] args){
TestStudent test = new TestStudent();
if (test.testAddResult() == true)
System.out.println("addResult = correct");
else
System.out.println("addResult = incorrect");
if (test.testGetGrades() == true)
System.out.println("getGrades = correct");
else
System.out.println("getGrades = incorrect");
if (test.testToString() == true)
System.out.println("toString = correct");
else
System.out.println("toString = incorrect");
if (test.testAverageGrade() == true)
System.out.println("averageGrade = correct");
else
System.out.println("averageGrade = incorrect");
if (test.testPrintResults() == true)
System.out.println("printResults = correct");
else
System.out.println("printResults = incorrect");
}
public boolean testAddResult(){
Grade grade = new Grade(11.7);
TeachingUnitResult unitResult = new TeachingUnitResult("Programmation 2", grade);
Student student = new Student("tt", "t morts");
student.addResult("Programmation 2", grade);
if (student.equals(unitResult))
return true;
else
return false;
}
public boolean testGetGrades(){
Grade grade = new Grade(11.7);
Student student = new Student("t","t");
student.addResult("Prog", grade);
List<Grade> grades = student.getGrades();
if (grades.contains(grade))
return true;
else
return false;
}
public boolean testToString(){
Student student = new Student("Leo", "Rangheard");
String name = student.toString();
if (name.equals("Leo Rangheard"))
return true;
else
return false;
}
public boolean testAverageGrade(){
Student student = new Student("t", "t");
student.addResult("Programmation 2", new Grade(8));
student.addResult("Programmation 2", new Grade(9));
student.addResult("Programmation 2", new Grade(10));
student.addResult("Programmation 2", new Grade(11));
student.addResult("Programmation 2", new Grade(12));
Grade averageGrade = student.getAverageGrade();
if (averageGrade.getValue() == 10)
return true;
else
return false;
}
public boolean testPrintResults(){
}
}
public class TestTeachingUnitResult {
public static void main(String [] args){
TestTeachingUnitResult test = new TestTeachingUnitResult();
if (test.testgetGrade() == true)
System.out.println("testgetGrade = correct");
else
System.out.println("testgetGrade = incorrect");
if (test.testtoString() == true)
System.out.println("testtoString = correct");
else
System.out.println("testtoString = incorrect");
}
public boolean testgetGrade(){
Grade grade = new Grade(11.5);
double valeur = grade.getValue();
if (valeur == 11.5)
return true;
else
return false;
}
public boolean testtoString(){
Grade grade = new Grade(11.7);
TeachingUnitResult test = new TeachingUnitResult("Programmation 2", grade);
String TURString = test.toString();
if (TURString.equals("Programmation 2 : 11.7/20"))
return true;
else
return false;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment