Skip to content
Snippets Groups Projects
Commit fe6270ac authored by Samuel Turpin's avatar Samuel Turpin :computer:
Browse files

tp4 Student Adds

parent 80fe4df9
Branches
No related tags found
No related merge requests found
package qdev4;
import tpQU.tp04.LocalKeyboard;
public class Ex2
{
public static int[] tab = {17, 12, 15, 38, 29, 157, 89, -22, 0, 5};
......
......@@ -6,13 +6,17 @@ public class Person
{
private String nom;
private LocalDate Birth;
public Person(String n, LocalDate d)
{
this.nom=n;
this.Birth=d;
}
public String getNom() {
return nom;
}
public long getAges()
{
return Birth.toEpochDay();
......
......@@ -2,6 +2,7 @@ package td08;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class Student
......@@ -34,6 +35,10 @@ public class Student
return this.person.getAges();
}
public String getINE() {
return INE;
}
public String getNom() {
return nom;
}
......@@ -49,13 +54,13 @@ public class Student
public void addGrade(String mat, double grade)
{
this.addGrade(Mat.valueOf(mat.toUpperCase()), grade);
this.addGrade(Mat.valueOf(mat.toUpperCase(Locale.ROOT)), grade);
}
public double computeOverall()
{
double calcul=0.0;
if(grades.size()==0)
if(grades.isEmpty())
{
return -1;
}
......@@ -65,8 +70,8 @@ public class Student
{
calcul=calcul+d;
}
double fCalc = calcul/grades.size();
return fCalc;
calcul = calcul/grades.size();
return calcul;
}
}
......@@ -75,12 +80,11 @@ public class Student
{
if(this.pedago)
{
return "true";
}
else
{
return "false";
}
return super.toString();
}
}
\ No newline at end of file
......@@ -2,8 +2,8 @@ package tp01;
public class HighScore
{
Score[] top;
private Score[] top;
public HighScore(int numberPod)
{
this.top = new Score[numberPod];
......@@ -12,38 +12,27 @@ public class HighScore
@Override
public String toString()
{
return "1. " + top[0] + "\n2. " + top[1] + "\n3. " + top[2];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < top.length; i++) {
sb.append((i + 1) + ". " + (top[i] != null ? top[i].toString() : "N/A") + "\n");
}
return sb.toString();
}
boolean ajout(Score newScore)
public boolean ajout(Score newScore)
{
for(int i = 0;i < top.length;)
for (int i = 0; i < top.length; i++)
{
if(top[i] != null)
if (top[i] == null || newScore.sc > top[i].sc)
{
if(newScore.sc > top[i].sc)
{
top[i+2] = top[i+1];
top[i+1] = top[i];
top[i] = newScore;
}
else if(newScore.sc > top[i+1].sc)
{
top[i+2] = top[i+1];
top[i+1] = newScore;
}
else if(newScore.sc > top[i+2].sc)
{
top[i+2] = newScore;
// Décale les éléments vers la droite pour faire de la place
for (int j = top.length - 1; j > i; j--) {
top[j] = top[j - 1];
}
return true;
}
else
{
top[i] = newScore;
return true;
}
}
return false;
}
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@ package tp04;
public class Person
{
private final int ID = 0;
private static final int ID = 0;
private String forename;
private String name;
......@@ -35,22 +35,11 @@ public class Person
this.name = name;
}
public boolean equals(Person p)
{
if(this == p)
{
return true;
}
if(this.ID == p.ID)
{
return true;
}
return false;
}
//Méthode equals non necessaire equals(Obj obj) { if(obj == this) }
@Override
public String toString()
{
return this.ID + ": " + this.forename + " " + this.name;
return getID() + ": " + getForename() + " " + getName();
}
}
\ No newline at end of file
package tp04;
public class Student extends Person
{
private double grades[] = {};
private static String forename;
private static String name;
private Person pers;
public Student(String f, String n)
{
super(f, n);
}
public Student(Person pers, double[] grades)
{
super(forename, name);
this.pers = pers;
this.grades = grades;
}
public Student(String forename, String name, double[] grades)
{
super(forename, name);
this.grades = grades;
}
public double[] getGrades() {
return grades;
}
public void addGrade(double aGrade)
{
this.grades[getGrades().length-1]=aGrade;
}
public Person getPers() {
return pers;
}
public boolean equals(Student stu)
{
return super.equals(stu) && stu.getGrades().length == this.getGrades().length;
}
public double getAverage()
{
double db = 0.0;
if(getGrades().length == 0)
{
return db;
}
else
{
for(int i = 0; i < getGrades().length; i++)
{
db = db + getGrades()[i];
}
db = db / getGrades().length;
return db;
}
}
@Override
public String toString()
{
return "Student["+getID()+": "+getPers().getForename()+" "+getPers().getName()+" = "+getAverage()+"]";
}
}
\ No newline at end of file
package tp04;
public class StudentAbs extends Student
{
public StudentAbs(Person pers, double[] grades)
{
super(pers, grades);
}
}
\ No newline at end of file
package tp04;
public class UseStudent
{
public static void main(String[] args)
{
Person alice = new Person("Alice", "A");
Person bruno = new Person("Bruno", "B");
Person samuel = new Person("Samuel", "T");
double note1[] = {10,16,10};
double note2[] = {15,9,6};
double note3[] = {8,19,13};
Student s1 = new Student(alice, note1);
Student s2 = new Student(bruno, note2);
Student s3 = new Student(samuel, note3);
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment