69 lines
1.9 KiB
Java
69 lines
1.9 KiB
Java
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)));
|
|
}
|
|
} |