From 212247b7b5a30017bd62209a72d20ceb243ea3b5 Mon Sep 17 00:00:00 2001 From: Alexis Nasr <alexis.nasr@lif.univ-mrs.fr> Date: Fri, 31 Jul 2020 11:46:42 +0200 Subject: [PATCH] ajout de tp1 --- tp1/Cohort.java | 53 +++++++++++++++++++++ tp1/Grade.java | 77 +++++++++++++++++++++++++++++++ tp1/Main.java | 14 ++++++ tp1/Student.java | 91 +++++++++++++++++++++++++++++++++++++ tp1/TeachingUnitResult.java | 38 ++++++++++++++++ 5 files changed, 273 insertions(+) create mode 100644 tp1/Cohort.java create mode 100644 tp1/Grade.java create mode 100644 tp1/Main.java create mode 100644 tp1/Student.java create mode 100644 tp1/TeachingUnitResult.java diff --git a/tp1/Cohort.java b/tp1/Cohort.java new file mode 100644 index 0000000..e199e79 --- /dev/null +++ b/tp1/Cohort.java @@ -0,0 +1,53 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * A group of students. + */ + +public class Cohort { + private final String name; + private final List<Student> students; + + /** + * Constructs a cohort with a name equals to the specified {@code name} and no students. + * @param name the name of the constructed Cohort + */ + + public Cohort(String name) { + this.name = name; + this.students = new ArrayList<>(); + } + + /** + * 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){ + } + + /** + * Returns the list of students of the cohort. + * @return the list of students of the cohort. + */ + public List<Student> getStudents(){ + } + + /** + * Print via the standard output the name of the cohort and all results associated to the students with their average + * grade. + */ + public void printStudentsResults(){ + } + + private void printName(){ + } + + /** + * Returns the name of the cohort. + * @return the name of the cohort + */ + @Override + public String toString() { + } +} diff --git a/tp1/Grade.java b/tp1/Grade.java new file mode 100644 index 0000000..f25893a --- /dev/null +++ b/tp1/Grade.java @@ -0,0 +1,77 @@ +import java.util.List; + +/** + * A grade with a float value comprised between 0 and 20. + * + */ +public class Grade { + /** + * The maximum value of a grade. + */ + private static final int MAXIMUM_GRADE = 20; + private final double value; + + /** + * Constructs a grade with a value equals to the specified {@code value}. + * + * @param value the value of the constructed grade + */ + + public Grade(double value) { + this.value = value; + } + + /** + * Returns the value of the grade as a double. + * + * @return the value of the grade + */ + + public double getValue() { + } + + /** + * Returns a string representation of the grade in the format X.X/20. + * @return a string representation of the grade + */ + @Override + public String toString() { + } + + /** + * Returns a grade with a value equals to the arithmetic mean of the values of the grade in + * the specified list. + * + * @param grades a list of grades + * @return a grade corresponding to the mean of grade in {@code grades} + */ + public static Grade averageGrade(List<Grade> grades){ + } + + /** + * Determines whether or not two grades are equal. Two instances of Grade are equal if the values + * of their {@code value} member field are the same. + * @param o an object to be compared with this Grade + * @return {@code true} if the object to be compared is an instance of Grade and has the same value; {@code false} + * otherwise. + */ + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Grade grade = (Grade) o; + + return Double.compare(grade.value, value) == 0; + } + + /** + * Returns a hash code value for the object. + * @return a hash code value for this object. + */ + @Override + public int hashCode() { + long temp = Double.doubleToLongBits(value); + return (int) (temp ^ (temp >>> 32)); + } +} diff --git a/tp1/Main.java b/tp1/Main.java new file mode 100644 index 0000000..48c9805 --- /dev/null +++ b/tp1/Main.java @@ -0,0 +1,14 @@ +public class Main { + public static void main(String[] args){ + Student student1 = new Student("Arnaud", "Labourel"); + Student student2 = new Student("Paul", "Calcul"); + student1.addResult("Programmation 2", new Grade(20)); + student2.addResult("Programmation 2", new Grade(0)); + student1.addResult("Structures discrètes", new Grade(20)); + student2.addResult("Structures discrètes", new Grade(0)); + Cohort cohort = new Cohort("L2 informatique"); + cohort.addStudent(student1); + cohort.addStudent(student2); + cohort.printStudentsResults(); + } +} diff --git a/tp1/Student.java b/tp1/Student.java new file mode 100644 index 0000000..193bd84 --- /dev/null +++ b/tp1/Student.java @@ -0,0 +1,91 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * A students with results. + */ + +public class Student { + private final String firstName; + private final String lastName; + private final List<TeachingUnitResult> results; + + /** + * Constructs a student with the specified first name and last name and no associated results. + * + * @param firstName the first name of the constructed student + * @param lastName the last name of the constructed student + */ + + public Student(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + this.results = new ArrayList<>(); + } + + /** + * Add a grade associated to a teaching unit to the results of the student. + * + * @param teachingUnitName the name of the teaching unit of the added result + * @param grade the grade of the added result + */ + public void addResult(String teachingUnitName, Grade grade){ + } + + /** + * Returns a string representation of the student in the format first name last name. + * @return a string representation of the student + */ + @Override + public String toString() { + } + + + /** + * Returns the grades of the student. + * + * @return the grades of the student + */ + public List<Grade> getGrades(){ + } + + /** + * Returns the average grade of the student. + * + * @return the average grade of the student + */ + public Grade getAverageGrade() { + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Student student = (Student) o; + + if (!firstName.equals(student.firstName)) return false; + return lastName.equals(student.lastName); + } + + @Override + public int hashCode() { + int result = firstName.hashCode(); + result = 31 * result + lastName.hashCode(); + return result; + } + + /** + * Print via the standard output the name of the student, all results associated to the students and + * the average grade of the student. + */ + public void printResults(){ + } + + private void printName() { + } + + private void printAverageGrade() { + } + +} diff --git a/tp1/TeachingUnitResult.java b/tp1/TeachingUnitResult.java new file mode 100644 index 0000000..c052586 --- /dev/null +++ b/tp1/TeachingUnitResult.java @@ -0,0 +1,38 @@ +/** + * A result corresponding to a grade associated with a teaching unit. + */ + +public class TeachingUnitResult { + private final String teachingUnitName; + private final Grade grade; + + + /** + * Constructs an instance of TeachingUnitResult with a grade equals to the specified {@code grade} + * and a teaching unit name equals to the specified {@code teachingUnitName}. + * + * @param teachingUnitName the name of the teaching unit of the constructed TeachingUnitResult + * @param grade the grade of the constructed TeachingUnitResult + */ + + public TeachingUnitResult(String teachingUnitName, Grade grade) { + this.teachingUnitName = teachingUnitName; + this.grade = grade; + } + + /** + * Returns the grade associated to the result. + * + * @return the grade associated to the result + */ + public Grade getGrade() { + } + + /** + * Returns a string representation of the result in the format Name of the teaching unit : X.X. + * @return a string representation of the result + */ + @Override + public String toString() { + } +} -- GitLab