From 07503b30048ffa045ce79d76ff561d29930821c1 Mon Sep 17 00:00:00 2001 From: Ethan Robert <ethan.rbrt90@gmail.com> Date: Fri, 7 Mar 2025 15:57:44 +0100 Subject: [PATCH] Added yearGroup and studentAbs classes --- src/tp04/StudentAbs.java | 101 +++++++++++++++++++++++++++++++++++++++ src/tp04/YearGroup.java | 54 +++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 src/tp04/StudentAbs.java create mode 100644 src/tp04/YearGroup.java diff --git a/src/tp04/StudentAbs.java b/src/tp04/StudentAbs.java new file mode 100644 index 0000000..d2ed361 --- /dev/null +++ b/src/tp04/StudentAbs.java @@ -0,0 +1,101 @@ +package tp04; + +public class StudentAbs { + public final static int thresholdAbs = 5; + + private Student etu; + private int abs; + + public StudentAbs(Person person, double[] grades, int abs) { + this.etu = new Student(person, grades); + this.abs = abs; + } + + public StudentAbs(String forename, String name, double[] grades, int abs) { + this.etu = new Student(forename, name, grades); + this.abs = abs; + } + + public StudentAbs(String forename, String name, double grade, int abs) { + this.etu = new Student(forename, name, grade); + this.abs = abs; + } + + public StudentAbs(String forename, String name, double grade) { + this.etu = new Student(forename, name, grade); + this.abs = 0; + } + + public String getName() { + return this.etu.getName(); + } + + public void setName(String newName) { + this.etu.setName(newName); + } + + public String getForename() { + return this.etu.getForename(); + } + + public void setForename(String newName) { + this.etu.setForename(newName); + } + + public int getID() { + return this.etu.getID(); + } + + public void addGrade(double grade) { + this.etu.addGrade(grade); + } + + public double[] getGrades() { + return this.etu.getGrades(); + } + + public double getAverage() { + return this.etu.getAverage(); + } + + public int getAbs() { + return this.abs; + } + + public void incrAbs() { + this.abs++; + } + + public String toString() { + return "" + this.etu + ", nbAbs=" + this.abs; + } + + public boolean equals(Object other) { + if (other == null) { + return false; + } + if (other.getClass() == this.getClass()) { + StudentAbs otherStudentAbs = (StudentAbs) other; + double[] thisStudentGrades = this.etu.getGrades(); + boolean arrayEquals = true; + double[] otherStudentGrades = otherStudentAbs.getGrades(); + if (otherStudentGrades.length == thisStudentGrades.length) { + for (int i = 0; i < thisStudentGrades.length; i++) { + arrayEquals = thisStudentGrades[i] == otherStudentGrades[i]; + } + } + return this.getID() == otherStudentAbs.getID() && arrayEquals && this.getAbs() == otherStudentAbs.getAbs(); + } + return false; + } + + public boolean warning() { + return this.abs > StudentAbs.thresholdAbs || this.etu.getAverage() < Student.thresholdAvg; + } + + public boolean validation() { + return !this.warning(); + } + + +} diff --git a/src/tp04/YearGroup.java b/src/tp04/YearGroup.java new file mode 100644 index 0000000..50a916d --- /dev/null +++ b/src/tp04/YearGroup.java @@ -0,0 +1,54 @@ +package tp04; + +import java.util.Arrays; + +public class YearGroup { + private StudentAbs[] yg; + + public YearGroup() { + this.yg = new StudentAbs[]; + } + + public int getRealLength() { + int count = 0; + for (int i = 0; i < this.yg.length; i++) { + if (this.yg[i] != null) { + count++; + } + } + return count; + } + + public void addStudent(StudentAbs student) { + if (this.yg.length != this.getRealLength()) { + for (int i = 0; i < this.yg.length; i++) { + if (this.yg[i] == null) { + this.yg[i] = student; + } + } + } else { + this.yg = Arrays.copyOf(this.yg, this.yg.length + 1); + this.yg[this.yg.length - 1] = student; + } + } + + public void addStudent(StudentAbs[] students) { + for (int i = 0; i < students.length; i++) { + this.addStudent(students[i]); + } + } + + public void addGrades(double[] grades) { + for (int i = 0; i < grades.length; i++) { + this.yg[i].addGrade(grades[i]); + } + } + + public void validation() { + for (int i = 0; i < this.yg.length; i++) { + if (this.yg[i].validation()) { + System.out.println(this.yg[i]); + } + } + } +} -- GitLab