Fin du TP Heritage

This commit is contained in:
Simoes Lukas
2025-02-06 14:32:11 +01:00
parent 209f320a5a
commit dd0903e9fc
21 changed files with 304 additions and 20 deletions

BIN
DEV2.1/TP04/Compteur.class Normal file

Binary file not shown.

16
DEV2.1/TP04/Compteur.java Normal file
View File

@@ -0,0 +1,16 @@
public class Compteur {
private int compte;
public Compteur() {
this.compte = 0;
}
public void plusUn() {
this.compte++;
}
public String toString() {
return Integer.toBinaryString(this.compte);
}
}

BIN
DEV2.1/TP04/Date.class Normal file

Binary file not shown.

69
DEV2.1/TP04/Date.java Normal file
View File

@@ -0,0 +1,69 @@
public class Date {
private int jour;
private int mois;
private int annee;
public Date(int j, int m, int a) {
this.jour = j;
this.mois = m;
this.annee = a;
}
public String toString() {
return "" + this.annee + "-" + this.mois + "-" + this.jour;
}
public Date lendemain() {
int[] joursParMois = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (this.jour == joursParMois[this.mois-1]) {
if (this.mois == 12) {
return new Date(1, 1, this.annee+1);
}
return new Date(1, this.mois+1, this.annee);
}
return new Date(this.jour+1, this.mois, this.annee);
}
public int getAnnee() {
return this.annee;
}
public int getMois() {
return this.mois;
}
public int getJour() {
return this.jour;
}
public boolean dateInferieureA(Date aComparer) {
return (this.annee < aComparer.getAnnee() || this.mois < aComparer.getMois() || this.jour < aComparer.getJour());
}
public boolean dateSuperieureA(Date aComparer) {
return (this.annee > aComparer.getAnnee() || this.mois > aComparer.getMois() || this.jour > aComparer.getJour());
}
public boolean dateEgaleA(Date aComparer) {
return (this.annee == aComparer.getAnnee() && this.mois == aComparer.getMois() && this.jour == aComparer.getJour());
}
public String compareDates(Date aComparer) {
/* Affiche si la date actuelle est inférieure, égale ou supérieure à la date aComparer */
if (this.dateEgaleA(aComparer)) {
return this.toString() + " est égale à " + aComparer.toString() ;
}
if (this.dateInferieureA(aComparer)) {
return this.toString() + " est inférieure à " + aComparer.toString() ;
}
return this.toString() + " est supérieure à " + aComparer.toString() ;
}
public static void main(String[] args) {
Date d = new Date(15,10,2025);
//System.out.println(d);
Date lendemain = d.lendemain();
//System.out.println(lendemain);
System.out.println(d.compareDates(new Date(17,9,2025)));
}
}

View File

BIN
DEV2.1/TP04/Periode.class Normal file

Binary file not shown.

35
DEV2.1/TP04/Periode.java Normal file
View File

@@ -0,0 +1,35 @@
public class Periode {
private Date debut;
private Date fin;
public Periode(Date debut, Date fin) {
this.debut = debut;
this.fin = fin;
}
public String toString() {
return this.debut.toString() + " - " + this.fin.toString();
}
public void rallongeUneJournee() {
this.fin = this.fin.lendemain();
}
public int nombreDeJours() {
int compteur = 0;
Date temp = this.debut;
while (!temp.dateEgaleA(this.fin)) {
compteur++;
temp = temp.lendemain();
}
return compteur;
}
public static void main(String[] args) {
Periode p = new Periode(new Date(12,2,2025), new Date(17,2,2025));
System.out.println(p);
p.rallongeUneJournee();
System.out.println(p);
System.out.println("Nombre de jours entre les 2 dates : " + p.nombreDeJours());
}
}

Binary file not shown.

View File

@@ -0,0 +1,12 @@
public class Progression {
public static void main(String[] args) {
Compteur c = new Compteur();
for (int i = 0; i < 5; i++) {
c.plusUn();
}
for (int i = 0; i < 5; i++) {
System.out.println(c.toString());
c.plusUn();
}
}
}

View File