Fin du TP Heritage
This commit is contained in:
35
DEV2.1/TP04/Periode.java
Normal file
35
DEV2.1/TP04/Periode.java
Normal file
@@ -0,0 +1,35 @@
|
||||
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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user