Skip to content
Snippets Groups Projects
Commit 07503b30 authored by Ethan Robert's avatar Ethan Robert
Browse files

Added yearGroup and studentAbs classes

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