apl/APL2.1/TP2_Classes_et_objets/Periode.java
unknown d9949b5cb0 a
2022-01-14 06:54:18 +01:00

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