a
This commit is contained in:
17
APL2.1/TP2_Classes_et_objets/Compteur.java
Normal file
17
APL2.1/TP2_Classes_et_objets/Compteur.java
Normal file
@@ -0,0 +1,17 @@
|
||||
public class Compteur {
|
||||
// attribut
|
||||
private int compte;
|
||||
// méthode
|
||||
public void plusUn() {
|
||||
this.compte++;
|
||||
}
|
||||
// autre méthode
|
||||
public String toString() {
|
||||
return Integer.toBinaryString(this.compte);
|
||||
}
|
||||
|
||||
// constructeur
|
||||
public Compteur(){
|
||||
this.compte=0;
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP2_Classes_et_objets/Date.class
Normal file
BIN
APL2.1/TP2_Classes_et_objets/Date.class
Normal file
Binary file not shown.
39
APL2.1/TP2_Classes_et_objets/Date.java
Normal file
39
APL2.1/TP2_Classes_et_objets/Date.java
Normal file
@@ -0,0 +1,39 @@
|
||||
public class Date{
|
||||
|
||||
public int day; //attribut
|
||||
public int month; //attribut
|
||||
public int year; //attribut
|
||||
|
||||
public Date(){ //constructeur
|
||||
this.day=28;
|
||||
this.month=01;
|
||||
this.year=2021;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return this.year+"-"+this.month+"-"+this.day ; // A partir du moment ou l'on concatene des elements, jai l'impression que c'est automatiquement consideré comme un String OU le fait que la methode renvoi un String fait automatiquement la conversion
|
||||
}
|
||||
|
||||
public String tomorowDate(){ // methode affichant la date de demain
|
||||
int tomorowDay=this.day, tomorowMonth=this.month, tomorowYear=this.year;
|
||||
if(tomorowDay<30){
|
||||
tomorowDay++;
|
||||
}else{
|
||||
tomorowDay=1;
|
||||
if(tomorowMonth<12){
|
||||
tomorowMonth++;
|
||||
}else{
|
||||
tomorowMonth=1;
|
||||
tomorowYear++;
|
||||
}
|
||||
}
|
||||
return tomorowYear+"-"+tomorowMonth+"-"+tomorowDay;
|
||||
}
|
||||
|
||||
public boolean dateCompare(String date, String dateCmpr){ // méthode permettant de comparer deux date
|
||||
|
||||
if(date==dateCmpr){
|
||||
return true;
|
||||
}else return false;
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP2_Classes_et_objets/Periode.class
Normal file
BIN
APL2.1/TP2_Classes_et_objets/Periode.class
Normal file
Binary file not shown.
49
APL2.1/TP2_Classes_et_objets/Periode.java
Normal file
49
APL2.1/TP2_Classes_et_objets/Periode.java
Normal file
@@ -0,0 +1,49 @@
|
||||
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
|
||||
12
APL2.1/TP2_Classes_et_objets/Progression.java
Normal file
12
APL2.1/TP2_Classes_et_objets/Progression.java
Normal file
@@ -0,0 +1,12 @@
|
||||
public class Progression{
|
||||
|
||||
public static void main(String[] args){
|
||||
Compteur objet = new Compteur();
|
||||
int compteur=0;
|
||||
for(compteur=0;compteur<5;compteur++)objet.plusUn();
|
||||
for(compteur=0;compteur<4;compteur++){
|
||||
objet.plusUn();
|
||||
System.out.println(objet);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
APL2.1/TP2_Classes_et_objets/TestDate.class
Normal file
BIN
APL2.1/TP2_Classes_et_objets/TestDate.class
Normal file
Binary file not shown.
21
APL2.1/TP2_Classes_et_objets/TestDate.java
Normal file
21
APL2.1/TP2_Classes_et_objets/TestDate.java
Normal file
@@ -0,0 +1,21 @@
|
||||
public class TestDate{
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
Date date = new Date();
|
||||
String date1 = "2021-02-28", date2 = "2031-01-28";
|
||||
|
||||
System.out.println("\nEXERCICE 2\n---------------");
|
||||
System.out.println("La date actuelle est : "+date.toString() );
|
||||
System.out.println("La date du lendemain est : "+date.tomorowDate() );
|
||||
|
||||
System.out.println("\nEXERCICE 3\n---------------");
|
||||
System.out.println("La premiere date est "+date1);
|
||||
System.out.println("La seconde date est "+date2);
|
||||
|
||||
if(date.dateCompare(date1, date2)){
|
||||
System.out.println("Les deux dates sont les mêmes");
|
||||
}else System.out.println("Les deux dates sont différentes");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user