DEV/DEV2.1/TP2/Date.java

73 lines
1.1 KiB
Java
Raw Normal View History

2023-02-13 11:26:06 +01:00
public class Date
{
private int jour;
private int mois;
private int annee;
public Date(int a, int m, int j)
{
this.jour = j;
this.mois = m;
this.annee = a;
}
public String lendemain()
{
if (this.jour<30)
{
return this.annee+"-"+this.mois+"-"+(this.jour+1);
}
else
{
if (this.mois<12)
{
return this.annee+"-"+(this.mois+1)+"-1";
}
else
{
return (this.annee+1)+"-1-1";
}
}
}
public String toString()
{
return this.annee+"-"+this.mois+"-"+this.jour;
}
public int datecmp(Date other)
{
if (this.annee==other.annee&&this.mois==other.mois&&this.jour==other.jour)
{
return 0;
}
else
{
if (this.annee>other.annee)
{
return 1;
}
else
{
if (this.mois>other.mois)
{
return 1;
}
else
{
if (this.jour>other.jour)
{
return 1;
}
else
{
return -1;
}
}
}
}
}
}
2023-03-27 11:21:24 +02:00