Files
DEV/DEV2.1/TP04/Periode.java
2025-02-06 14:32:11 +01:00

35 lines
775 B
Java

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());
}
}