Salut, alors j'ai corrigé mon code et ca donne :
class Pers
{
private String date ; // format "jj/mm/aaaa", ex : "25/12/1993"
private int cafe ;
public Pers(String dat, int caf)
{ date = dat;
cafe = caf;
}
public Pers(String dat)
{
date = dat;
cafe = 3;
}
public Pers(int caf)
{
cafe = caf;
date = "17/12/1990";
}
public String getMois()
{
String[] nomMois = {"janvier", "f?vrier", "mars", "avril",
"mai", "juin", "juillet", "aout", "septembre",
"octobre", "novembre", "d?cembre" };
int indMois = Integer.parseInt(date.substring(3,5))%50 - 1;
return nomMois[indMois];
}
public void afficher(String message)
{
System.out.printf("%s n?(e)le %s ", message,
date.substring(1,3));
System.out.printf("%s ", getMois());
System.out.printf("19%s consomme %.1d tasse(s) de café\n",
cafe);
}
public String getDat()
{
return date;
}
public int getCafe()
{
return cafe;
}
public void setCafe(int nouvCaf)
{
cafe = nouvCaf;
}
}// fin personne
public class TP3D1 {
int cafe, pers, nbPers ;
static void afficher(Pers[] p, int nbPers)
{
System.out.printf("Contenu du tableau des personnes :\n");
for(int i = 0; i < nbPers; i++)
System.out.printf("%3d) %15s %10.1d\n", i, p[i].getDat(), p[i].getCafe());
System.out.printf("\n\n");
}
public static void main(String[] args) {
Pers p1 = new Pers("19/11/1995", 3),
p2 = new Pers("17/12/1990"),// par défaut 0 tasse de café
p3 = new Pers("12/11/1991"),
p4 = new Pers("30/09/1991"),
p5 = new Pers("19/10/1994", 7);
p1.afficher("Infos de p1 : ");
p1.setCafe(p1.getCafe() -1);
p1.afficher("Nouvelle conso cafe p1 : ");
p2.afficher("Infos de p2 : ");
p3.afficher("Infos de p3 : ");
p4.afficher("Infos de p4 : ");
p5.afficher("Infos de p5 : ");
p5.setCafe(p5.getCafe() -1);
p5.afficher("Nouvelle conso cafe p5 : ");
Pers[] p = { new Pers("19/11/1995", 3),
new Pers("17/12/1990"),
new Pers("12/11/1991"),
new Pers("30/09/1991"),
new Pers("19/10/1994", 7)};
int nbPers = p.length;
TP3D1.afficher(p, nbPers);
}
}
Le code ne comporte pas d'erreur, il affiche la premiere information, et apres j'ai un truc chelou, voici le C/C de l'exec :
Infos de p1 : n?(e)le 9/ novembre ''Exception in thread "main" java.util.IllegalFormatPrecisionException: 1
at java.util.Formatter$FormatSpecifier.checkInteger(Unknown Source)
at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
at java.util.Formatter.parse(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.io.PrintStream.format(Unknown Source)
at java.io.PrintStream.printf(Unknown Source)
at Pers.afficher(TP3D1.java:38)
at TP3D1.main(TP3D1.java:86)
''