1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| class CompteurCompose
{
CompteurSimple cpt;
static CompteurCompose cpt2,cpt3;
static int nbcpt;
CompteurCompose(CompteurSimple compt)
{
cpt=compt;
nbcpt=1;
}
CompteurCompose(CompteurSimple compt, CompteurCompose compt2)
{
cpt=compt;
cpt2=compt2;
nbcpt=2;
}
CompteurCompose(CompteurSimple compt, CompteurCompose compt2, CompteurCompose compt3)
{
cpt=compt;
cpt2=compt2;
cpt3=compt3;
nbcpt=3;
System.out.println(nbcpt);
}
void inc()
{
if(cpt.inc() && nbcpt>1)
{
if(cpt2.cpt.inc() && nbcpt>2)
cpt3.cpt.inc();
}
}
void affiche()
{
System.out.println(nbcpt);
if(nbcpt>2)
cpt3.cpt.affiche();
if(nbcpt>1)
cpt2.cpt.affiche();
cpt.affiche();
System.out.println();
}
public static void main(String[] args)
{
int i;
CompteurCompose c;
c=new CompteurCompose(new CompteurSimple(0,59,"Minute"),new CompteurCompose(new CompteurSimple(0,23,"Heure"),new CompteurCompose(new CompteurSimple(1,365,"Jour"))));
c.affiche();
for(i=1;i<10000;i++)
c.inc();
c.affiche();
}
} |
Partager