DEV/DEV2.1/TP2:ClassesEtObjets/Periode.java

41 lines
847 B
Java
Raw Normal View History

2023-02-13 11:29:17 +01:00
public class Periode{
private int nbrjour;
private Date n;
private Date m;
public Periode(Date a, Date b){
this.n=a;
this.m=b;
this.nbrjour=((b.annee-a.annee)*365)+((b.mois-a.mois)*31)+(b.jour-a.jour);
}
public String toString(){
return System.out.println("L'intervalle entre "+this.n.toString+" et "+this.m.toString+" est de "+this.nbrjour+"jour(s)");
}
public void prolongePeriode(){
this.m=this.m.lendemain;
this.nbrjour++;
}
public int intervalle(){
return this.nbrjour;
}
public static void main(String[] args) {
Date d = new Date();
Date l = d.lendemain();
Periode p = new Periode(d,l);
Periode i = new Periode(d,l);
i.prolongePeriode();
i.prolongePeriode();
int n = p.intervalle();
p.toString();
i.toString();
System.out.println(p);
System.out.println(i);
System.out.println(n);
}
}