debut classe et objet

This commit is contained in:
Simon SAYE BABU 2023-02-13 11:26:06 +01:00
parent 9751315d1a
commit df7f3f911b
5 changed files with 118 additions and 0 deletions

BIN
DEV2.1/TP2/Compteur.class Normal file

Binary file not shown.

29
DEV2.1/TP2/Compteur.java Normal file
View File

@ -0,0 +1,29 @@
public class Compteur
{
private int compte;
public Compteur(int start)
{
this.compte = start;
}
public void plusUn()
{
this.compte++;
}
public String toString()
{
return Integer.toBinaryString(this.compte);
}
public static void main(String[] args)
{
Compteur test = new Compteur(5);
while (test.compte<10)
{
System.out.println(test.toString());
test.plusUn();
}
}
}

BIN
DEV2.1/TP2/Date.class Normal file

Binary file not shown.

79
DEV2.1/TP2/Date.java Normal file
View File

@ -0,0 +1,79 @@
public class Date
{
private int jour;
private int mois;
private int annee;
public Date(int a, int m, int j)
{
this.jour = j;
this.mois = m;
this.annee = a;
}
public String lendemain()
{
if (this.jour<30)
{
return this.annee+"-"+this.mois+"-"+(this.jour+1);
}
else
{
if (this.mois<12)
{
return this.annee+"-"+(this.mois+1)+"-1";
}
else
{
return (this.annee+1)+"-1-1";
}
}
}
public String toString()
{
return this.annee+"-"+this.mois+"-"+this.jour;
}
public int datecmp(Date other)
{
if (this.annee==other.annee&&this.mois==other.mois&&this.jour==other.jour)
{
return 0;
}
else
{
if (this.annee>other.annee)
{
return 1;
}
else
{
if (this.mois>other.mois)
{
return 1;
}
else
{
if (this.jour>other.jour)
{
return 1;
}
else
{
return -1;
}
}
}
}
}
public static void main(String[] args)
{
Date test = new Date(2023,12,30);
System.out.println(test.toString());
System.out.println(test.lendemain());
}
}

10
DEV2.1/TP2/Periode.java Normal file
View File

@ -0,0 +1,10 @@
public class Periode
{
private int jour;
public Periode(int j)
{
this.jour = j;
}
}