Ajout des exo 2 et 3 du TP4
This commit is contained in:
BIN
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO2 et 3/Partie1/Date.class
Normal file
BIN
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO2 et 3/Partie1/Date.class
Normal file
Binary file not shown.
27
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO2 et 3/Partie1/Date.java
Normal file
27
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO2 et 3/Partie1/Date.java
Normal file
@@ -0,0 +1,27 @@
|
||||
public class Date{
|
||||
|
||||
// Attribut
|
||||
private int jour;
|
||||
private int mois;
|
||||
private int annee;
|
||||
|
||||
// Constructeur
|
||||
public Date(){
|
||||
this.jour = 18;
|
||||
this.mois = 2;
|
||||
this.annee = 2024;
|
||||
}
|
||||
|
||||
// Méthode
|
||||
public String toString() {
|
||||
String dateString = String.format("%d/%02d/%02d", this.annee, this.mois, this.jour); // Format ISO 8601 = AAAA/MM/JJ
|
||||
System.out.println(dateString);
|
||||
return dateString;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String args[]){
|
||||
Date date = new Date();
|
||||
date.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user