13 Fevrier

This commit is contained in:
2023-02-13 11:29:17 +01:00
parent bc03374f78
commit 3e5709c01d
19 changed files with 289 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,98 @@
public class Date{
public int annee;
public int mois;
public int jour;
public Date() {
this.annee=2023;
this.mois=02;
this.jour=13;
}
public String toString() {
return (String.format("%04d",this.annee)+"/"+String.format("%02d",this.mois)+"/"+String.format("%02d",this.jour));
}
public Date lendemain(){
Date res = new Date();
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){
res.jour=1;
if (this.mois==12){
res.mois=1;
res.annee=this.annee+1;
}else{
res.mois=this.mois+1;
res.annee=this.annee;
}
}else{
res.jour=this.jour+1;
res.mois=this.mois;
res.annee=this.annee;
}
}else{
if(this.mois==2){
if (this.jour>=28){
res.jour=1;
res.mois=this.mois+1;
res.annee=this.annee;
}else{
res.jour=this.jour+1;
res.mois=this.mois;
res.annee=this.annee;
}
}else{
if (this.jour>=30){
res.jour=1;
res.mois=this.mois+1;
res.annee=this.annee;
}else{
res.jour=this.jour+1;
res.mois=this.mois;
res.annee=this.annee;
}
}
} return res;
}
public int datecmp(Date b){
if (this.annee<b.annee){
return -1;
}else if (this.annee>b.annee){
return 1;
}else{
if (this.mois<b.mois){
return -1;
}else if (this.mois>b.mois){
return 1;
}else{
if (this.jour<b.jour){
return -1;
}else if (this.jour>b.jour){
return 1;
}else{
return 0;
}
}
}
}
public static void main(String[] args) {
Date d = new Date();
Date l = d.lendemain();
d.toString();
l.toString();
System.out.println("La date est:"+" "+d);
System.out.println("Le lendemain de "+d+" est:"+" "+l);
int cmp = d.datecmp(l);
if (cmp==-1){
System.out.println("La date "+d+" est plus petite que la date "+l);
}else if (cmp==1){
System.out.println("La date "+d+" est plus grande que la date "+l);
}else{
System.out.println("La date "+d+" est egale a la date "+l);
}
}
}

View File

@@ -0,0 +1,41 @@
public class Periode{
private int nbrjour;
private Date n;
private Date m;
public Periode(Date a, Date b){
this.n=a;
this.m=b;
this.nbrjour=((b.annee-a.annee)*365)+((b.mois-a.mois)*31)+(b.jour-a.jour);
}
public String toString(){
return System.out.println("L'intervalle entre "+this.n.toString+" et "+this.m.toString+" est de "+this.nbrjour+"jour(s)");
}
public void prolongePeriode(){
this.m=this.m.lendemain;
this.nbrjour++;
}
public int intervalle(){
return this.nbrjour;
}
public static void main(String[] args) {
Date d = new Date();
Date l = d.lendemain();
Periode p = new Periode(d,l);
Periode i = new Periode(d,l);
i.prolongePeriode();
i.prolongePeriode();
int n = p.intervalle();
p.toString();
i.toString();
System.out.println(p);
System.out.println(i);
System.out.println(n);
}
}

Binary file not shown.

View File

@@ -0,0 +1,26 @@
public class Progression{
// attribut
private int compte;
// methode
public void plusUn() {
this.compte++;
}
// autre methode
public String toString() {
return Integer.toBinaryString(this.compte);
}
public static void main(String[] args) {
Progression n = new Progression();
n.compte = 5;
int s=5;
for(int i = 0;i<5;i++){
n.toString();
System.out.println("L'ecriture binaire de "+s+" est: "+n);
n.plusUn();
s++;
}
}
}