Ajout des exo 2 et 3 du TP4
This commit is contained in:
BIN
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO1/binaire.class
Normal file
BIN
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO1/binaire.class
Normal file
Binary file not shown.
12
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO1/binaire.java
Normal file
12
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO1/binaire.java
Normal file
@@ -0,0 +1,12 @@
|
||||
public class binaire{
|
||||
public static void main(String args[]){
|
||||
compteur mon_compteur = new compteur();
|
||||
for(int i = 0; i<5; i++){
|
||||
mon_compteur.plusUn();
|
||||
}
|
||||
for(int i = 5; i<9; i++){
|
||||
System.out.println(mon_compteur.toString());
|
||||
mon_compteur.plusUn();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO1/compteur.class
Normal file
BIN
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO1/compteur.class
Normal file
Binary file not shown.
18
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO1/compteur.java
Normal file
18
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO1/compteur.java
Normal file
@@ -0,0 +1,18 @@
|
||||
public class compteur {
|
||||
// attribut
|
||||
private int compte;
|
||||
// méthode
|
||||
|
||||
public compteur() {
|
||||
this.compte = 0;
|
||||
}
|
||||
|
||||
public void plusUn() {
|
||||
this.compte++;
|
||||
}
|
||||
// autre méthode
|
||||
public String toString() {
|
||||
return Integer.toBinaryString(this.compte);
|
||||
}
|
||||
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
BIN
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO2 et 3/Partie2/Date.class
Normal file
BIN
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO2 et 3/Partie2/Date.class
Normal file
Binary file not shown.
99
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO2 et 3/Partie2/Date.java
Normal file
99
BUT1/DEV2.1/TP4-ClassesEtObjets/EXO2 et 3/Partie2/Date.java
Normal file
@@ -0,0 +1,99 @@
|
||||
public class Date{
|
||||
|
||||
// Attribut
|
||||
private int jour;
|
||||
private int mois;
|
||||
private int annee;
|
||||
|
||||
// Constructeur
|
||||
public Date(int jour, int mois, int annee){
|
||||
this.jour = jour;
|
||||
this.mois = mois;
|
||||
this.annee = annee;
|
||||
}
|
||||
|
||||
// Méthode pour afficher la date
|
||||
public String toString() {
|
||||
return String.format("%d/%02d/%02d", this.annee, this.mois, this.jour); // Format ISO 8601 = AAAA/MM/JJ;
|
||||
}
|
||||
|
||||
// Méthode pour donner le lendemain d'une date
|
||||
public Date lendemain() {
|
||||
int jourLendemain = this.jour;
|
||||
int moisLendemain = this.mois;
|
||||
int anneeLendemain = this.annee;
|
||||
|
||||
if(this.mois == 1 || this.mois == 3 || this.mois == 5 || this.mois == 7 || this.mois == 8 || this.mois == 10 || this.mois == 12){
|
||||
if (this.jour == 31) {
|
||||
jourLendemain = 1;
|
||||
if (this.mois == 12) {
|
||||
moisLendemain = 1;
|
||||
anneeLendemain += 1;
|
||||
} else {
|
||||
moisLendemain += 1;
|
||||
}
|
||||
} else {
|
||||
jourLendemain += 1;
|
||||
}
|
||||
}else{
|
||||
if (this.jour == 30) {
|
||||
jourLendemain = 1;
|
||||
if (this.mois == 12) {
|
||||
moisLendemain = 1;
|
||||
anneeLendemain += 1;
|
||||
} else {
|
||||
moisLendemain += 1;
|
||||
}
|
||||
} else {
|
||||
jourLendemain += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return new Date(jourLendemain, moisLendemain, anneeLendemain);
|
||||
}
|
||||
|
||||
public Date comparerDate(Date date1, Date date2){
|
||||
// Si l'année de la date 1 est plus grande que l'année de la date 2
|
||||
if(date1.annee > date2.annee){
|
||||
return date1;
|
||||
}
|
||||
|
||||
// Si l'année de la date 2 est plus grande que l'année de la date 1
|
||||
if(date1.annee < date2.annee){
|
||||
return date2;
|
||||
}
|
||||
|
||||
// Si l'année de la date 1 est égale à l'année de la date 2 = on ne peut pas se fier à l'année et on passe aux mois
|
||||
if(date1.annee == date2.annee){
|
||||
if(date1.mois > date2.mois){
|
||||
return date1;
|
||||
}
|
||||
if(date1.mois < date2.mois){
|
||||
return date2;
|
||||
}
|
||||
if(date1.mois == date2.mois){
|
||||
if(date1.jour > date2.jour){
|
||||
return date1;
|
||||
}
|
||||
if(date1.jour < date2.jour){
|
||||
return date2;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
Date date = new Date(31,12,2024);
|
||||
Date dateLendemain = date.lendemain();
|
||||
|
||||
System.out.println("Aujourd'hui : " + date);
|
||||
System.out.println("Demain : " + dateLendemain);
|
||||
|
||||
System.out.println(date.comparerDate(date,dateLendemain));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user