Skip to content
Snippets Groups Projects
Commit 212247b7 authored by Alexis Nasr's avatar Alexis Nasr
Browse files

ajout de tp1

parent fe87fe47
Branches
No related tags found
No related merge requests found
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() {
}
}
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));
}
}
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();
}
}
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() {
}
}
/**
* 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() {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment