98 lines
2.0 KiB
Java
98 lines
2.0 KiB
Java
|
|
public class Date{
|
|
|
|
public int annee;
|
|
public int mois;
|
|
public int jour;
|
|
|
|
public Date() {
|
|
this.annee=2023;
|
|
this.mois=02;
|
|
this.jour=13;
|
|
}
|
|
|
|
public String toString() {
|
|
return (String.format("%04d",this.annee)+"/"+String.format("%02d",this.mois)+"/"+String.format("%02d",this.jour));
|
|
}
|
|
|
|
public Date lendemain(){
|
|
Date res = new Date();
|
|
if(this.mois==1||this.mois==3||this.mois==5||this.mois==7||this.mois==8||this.mois==10||this.mois>=12){
|
|
if (this.jour>=31){
|
|
res.jour=1;
|
|
if (this.mois==12){
|
|
res.mois=1;
|
|
res.annee=this.annee+1;
|
|
}else{
|
|
res.mois=this.mois+1;
|
|
res.annee=this.annee;
|
|
}
|
|
}else{
|
|
res.jour=this.jour+1;
|
|
res.mois=this.mois;
|
|
res.annee=this.annee;
|
|
}
|
|
}else{
|
|
if(this.mois==2){
|
|
if (this.jour>=28){
|
|
res.jour=1;
|
|
res.mois=this.mois+1;
|
|
res.annee=this.annee;
|
|
}else{
|
|
res.jour=this.jour+1;
|
|
res.mois=this.mois;
|
|
res.annee=this.annee;
|
|
}
|
|
}else{
|
|
if (this.jour>=30){
|
|
res.jour=1;
|
|
res.mois=this.mois+1;
|
|
res.annee=this.annee;
|
|
}else{
|
|
res.jour=this.jour+1;
|
|
res.mois=this.mois;
|
|
res.annee=this.annee;
|
|
}
|
|
}
|
|
} return res;
|
|
}
|
|
|
|
public int datecmp(Date b){
|
|
if (this.annee<b.annee){
|
|
return -1;
|
|
}else if (this.annee>b.annee){
|
|
return 1;
|
|
}else{
|
|
if (this.mois<b.mois){
|
|
return -1;
|
|
}else if (this.mois>b.mois){
|
|
return 1;
|
|
}else{
|
|
if (this.jour<b.jour){
|
|
return -1;
|
|
}else if (this.jour>b.jour){
|
|
return 1;
|
|
}else{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
Date d = new Date();
|
|
Date l = d.lendemain();
|
|
d.toString();
|
|
l.toString();
|
|
System.out.println("La date est:"+" "+d);
|
|
System.out.println("Le lendemain de "+d+" est:"+" "+l);
|
|
int cmp = d.datecmp(l);
|
|
if (cmp==-1){
|
|
System.out.println("La date "+d+" est plus petite que la date "+l);
|
|
}else if (cmp==1){
|
|
System.out.println("La date "+d+" est plus grande que la date "+l);
|
|
}else{
|
|
System.out.println("La date "+d+" est egale a la date "+l);
|
|
}
|
|
}
|
|
} |