49 lines
1.2 KiB
Java
49 lines
1.2 KiB
Java
public class Periode{
|
|
|
|
private Date date = new Date();
|
|
private int intervalle; //attribut
|
|
|
|
public Periode(Date dateDepart){ //constructeur
|
|
this.intervalle=0;
|
|
this.date=dateDepart;
|
|
}
|
|
|
|
public String toString(){
|
|
return this.intervalle+"0";
|
|
}
|
|
|
|
public int prolongePeriode(){
|
|
int intervalleProlonge=this.intervalle++;
|
|
return intervalleProlonge;
|
|
}
|
|
|
|
public void calculIntervalle(String dateCmpr){
|
|
|
|
String cmprYear = dateCmpr.substring(0,4);
|
|
int integerCmprYear = Integer.parseInt(cmprYear);
|
|
|
|
String cmprMonth = dateCmpr.substring(5,7);
|
|
int integerCmprMonth = Integer.parseInt(cmprMonth);
|
|
|
|
String cmprDay = dateCmpr.substring(8,10);
|
|
int integerCmprDay = Integer.parseInt(cmprDay);
|
|
|
|
int intervalle=0;
|
|
|
|
if(integerCmprYear>this.date.year){
|
|
intervalle+=365*integerCmprYear-this.date.year;
|
|
intervalle+=30*this.date.month;
|
|
intervalle+=this.date.day;
|
|
}else{
|
|
if(integerCmprMonth>this.date.month){
|
|
intervalle+=30*this.date.month;
|
|
intervalle+=this.date.day;
|
|
}else{
|
|
if(this.date.day<integerCmprDay) intervalle+=this.date.day;
|
|
}
|
|
}
|
|
|
|
System.out.println("L'intervalle "+dateCmpr+" -> "+date.toString()+" est de " +intervalle+" jours ");
|
|
}
|
|
}
|
|
//CODE NON FONCTIONEL |