update
This commit is contained in:
24
DEV/DEV2.1/TP04_Classes_et_objets/Compteur.java
Normal file
24
DEV/DEV2.1/TP04_Classes_et_objets/Compteur.java
Normal file
@@ -0,0 +1,24 @@
|
||||
public class Compteur {
|
||||
|
||||
private int compte;
|
||||
|
||||
public Compteur() {
|
||||
this.compte = 0;
|
||||
}
|
||||
|
||||
public int getValue(){
|
||||
return this.compte;
|
||||
}
|
||||
|
||||
public Compteur(int value) {
|
||||
this.compte = value;
|
||||
}
|
||||
|
||||
public void plusUn() {
|
||||
this.compte++;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return Integer.toBinaryString(this.compte);
|
||||
}
|
||||
}
|
0
DEV/DEV2.1/TP04_Classes_et_objets/Compteur.java~
Normal file
0
DEV/DEV2.1/TP04_Classes_et_objets/Compteur.java~
Normal file
BIN
DEV/DEV2.1/TP04_Classes_et_objets/Date.class
Normal file
BIN
DEV/DEV2.1/TP04_Classes_et_objets/Date.class
Normal file
Binary file not shown.
51
DEV/DEV2.1/TP04_Classes_et_objets/Date.java
Normal file
51
DEV/DEV2.1/TP04_Classes_et_objets/Date.java
Normal file
@@ -0,0 +1,51 @@
|
||||
public class Date{
|
||||
protected int annee;
|
||||
protected int mois;
|
||||
protected int jour;
|
||||
protected static int[] jourDuMois = {31,28,31,30,31,30,31,31,30,31,30,31};
|
||||
|
||||
public Date(int annee, int mois, int jour){
|
||||
this.annee = annee;
|
||||
this.mois = mois;
|
||||
this.jour = jour;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String stringAnnee = add0(this.annee, 4);
|
||||
String stringMois = add0(this.mois, 2);
|
||||
String stringJour = add0(this.jour, 2);
|
||||
return stringAnnee + "-" + stringMois + "-" + stringJour;
|
||||
}
|
||||
|
||||
public void lendemain(){
|
||||
this.jour ++;
|
||||
if (this.jour > Date.jourDuMois[this.mois-1]){
|
||||
this.jour = 1;
|
||||
this.mois ++;
|
||||
if (this.mois > 12){
|
||||
this.mois = 1;
|
||||
this.annee ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean compare(Date date){
|
||||
if (this.annee == date.annee && this.mois == date.mois && this.jour == date.jour){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String add0(int nombre, int taille){
|
||||
int puissance10 = 1;
|
||||
String resultat = Integer.toString(nombre);
|
||||
for (int i=1; i<taille ; i++){
|
||||
puissance10 *= 10;
|
||||
}
|
||||
while (nombre<puissance10){
|
||||
resultat = "0" + resultat;
|
||||
nombre *= 10;
|
||||
}
|
||||
return resultat;
|
||||
}
|
||||
}
|
51
DEV/DEV2.1/TP04_Classes_et_objets/Date.java~
Normal file
51
DEV/DEV2.1/TP04_Classes_et_objets/Date.java~
Normal file
@@ -0,0 +1,51 @@
|
||||
public class Date{
|
||||
private int annee;
|
||||
private int mois;
|
||||
private int jour;
|
||||
private static int[] jourDuMois = {31,28,31,30,31,30,31,31,30,31,30,31};
|
||||
|
||||
public Date(int annee, int mois, int jour){
|
||||
this.annee = annee;
|
||||
this.mois = mois;
|
||||
this.jour = jour;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
String stringAnnee = add0(this.annee, 4);
|
||||
String stringMois = add0(this.mois, 2);
|
||||
String stringJour = add0(this.jour, 2);
|
||||
return stringAnnee + "-" + stringMois + "-" + stringJour;
|
||||
}
|
||||
|
||||
public void lendemain(){
|
||||
this.jour ++;
|
||||
if (this.jour > Date.jourDuMois[this.mois-1]){
|
||||
this.jour = 1;
|
||||
this.mois ++;
|
||||
if (this.mois > 12){
|
||||
this.mois = 1;
|
||||
this.annee ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean compare(Date date){
|
||||
if (this.annee == date.annee && this.mois == date.mois && this.jour == date.jour){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String add0(int nombre, int taille){
|
||||
int puissance10 = 1;
|
||||
String resultat = Integer.toString(nombre);
|
||||
for (int i=1; i<taille ; i++){
|
||||
puissance10 *= 10;
|
||||
}
|
||||
while (nombre<puissance10){
|
||||
resultat = "0" + resultat;
|
||||
nombre *= 10;
|
||||
}
|
||||
return resultat;
|
||||
}
|
||||
}
|
9
DEV/DEV2.1/TP04_Classes_et_objets/Q1_Progression.java
Normal file
9
DEV/DEV2.1/TP04_Classes_et_objets/Q1_Progression.java
Normal file
@@ -0,0 +1,9 @@
|
||||
public class Q1_Progression {
|
||||
public static void main(String[] args) {
|
||||
Compteur c = new Compteur(5);
|
||||
do {
|
||||
System.out.println(c.toString());
|
||||
c.plusUn();
|
||||
} while (c.getValue() <=9);
|
||||
}
|
||||
}
|
9
DEV/DEV2.1/TP04_Classes_et_objets/Q1_Progression.java~
Normal file
9
DEV/DEV2.1/TP04_Classes_et_objets/Q1_Progression.java~
Normal file
@@ -0,0 +1,9 @@
|
||||
public class Q1_Progression {
|
||||
public static void main(String[] args) {
|
||||
Compteur c = new Compteur(5);
|
||||
do {
|
||||
System.out.println(c.toString());
|
||||
c.plusUn();
|
||||
} while (c.getValue() <=9);
|
||||
}
|
||||
}
|
BIN
DEV/DEV2.1/TP04_Classes_et_objets/Q2_Date.class
Normal file
BIN
DEV/DEV2.1/TP04_Classes_et_objets/Q2_Date.class
Normal file
Binary file not shown.
14
DEV/DEV2.1/TP04_Classes_et_objets/Q2_Date.java
Normal file
14
DEV/DEV2.1/TP04_Classes_et_objets/Q2_Date.java
Normal file
@@ -0,0 +1,14 @@
|
||||
public class Q2_Date {
|
||||
public static void main(String[] args) {
|
||||
Date today = new Date(2023, 2, 23);
|
||||
Date mariage = new Date(2023, 3, 1);
|
||||
for (int i=0; i<10 ; i++){
|
||||
System.out.print(today);
|
||||
if (today.compare(mariage)){
|
||||
System.out.print(" = Jour de mariage !!!");
|
||||
}
|
||||
System.out.println("");
|
||||
today.lendemain();
|
||||
}
|
||||
}
|
||||
}
|
14
DEV/DEV2.1/TP04_Classes_et_objets/Q2_Date.java~
Normal file
14
DEV/DEV2.1/TP04_Classes_et_objets/Q2_Date.java~
Normal file
@@ -0,0 +1,14 @@
|
||||
public class Q2_Date {
|
||||
public static void main(String[] args) {
|
||||
Date jourRandom = new Date(2023, 2, 23);
|
||||
Date mariage = new Date(2023, 3, 1);
|
||||
for (int i=0; i<10 ; i++){
|
||||
System.out.print(jourRandom);
|
||||
if (jourRandom.compare(mariage)){
|
||||
System.out.print(" = Jour de mariage !!!");
|
||||
}
|
||||
System.out.println("");
|
||||
jourRandom.lendemain();
|
||||
}
|
||||
}
|
||||
}
|
35
DEV/DEV2.1/TP04_Classes_et_objets/Q4_Periode.java
Normal file
35
DEV/DEV2.1/TP04_Classes_et_objets/Q4_Periode.java
Normal file
@@ -0,0 +1,35 @@
|
||||
public class Periode extends Date{
|
||||
protected int interval;
|
||||
protected int anneeFin;
|
||||
protected int moisFin;
|
||||
protected int jourFin;
|
||||
|
||||
public Periode(int anneeDebut, int moisDebut, int jourDebut, int anneeFin, int moisFin, int jourFin){
|
||||
super(anneeDebut, moisDebut, jourDebut);
|
||||
this.anneeFin = anneeFin;
|
||||
this.moisFin = moisFin;
|
||||
this.jourFin = jourFin;
|
||||
this.interval = compteurJour();
|
||||
}
|
||||
|
||||
public int compteurJour(){
|
||||
int compteur = 0;
|
||||
compteur += this.anneeFin*365;
|
||||
for (i=0 ; i<this.moisFin ; i++){
|
||||
compteur += this.jourDuMois[i];
|
||||
}
|
||||
compteur += this.jourFin;
|
||||
|
||||
compteur -= this.anneeDebut*365;
|
||||
for (i=0 ; i<this.moisDebut ; i++){
|
||||
compteur -= this.jourDuMois[i];
|
||||
}
|
||||
compteur -= this.jourDebut;
|
||||
|
||||
return compteur;
|
||||
}
|
||||
|
||||
public void(){
|
||||
this.lendemain
|
||||
}
|
||||
}
|
0
DEV/DEV2.1/TP04_Classes_et_objets/Q4_Periode.java~
Normal file
0
DEV/DEV2.1/TP04_Classes_et_objets/Q4_Periode.java~
Normal file
Reference in New Issue
Block a user