<java>composition
Fermé
domxaline
Messages postés
188
Date d'inscription
lundi 16 mai 2005
Statut
Membre
Dernière intervention
7 mars 2018
-
3 juin 2010 à 09:42
domxaline Messages postés 188 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 7 mars 2018 - 3 juin 2010 à 10:58
domxaline Messages postés 188 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 7 mars 2018 - 3 juin 2010 à 10:58
A voir également:
- <java>composition
- Waptrick java football - Télécharger - Jeux vidéo
- Java apk - Télécharger - Langages
- Jeux java itel football - Télécharger - Jeux vidéo
- Jeux java itel 5360 ✓ - Forum Mobile
- Java jre - Télécharger - Langages
2 réponses
xav3601
Messages postés
3288
Date d'inscription
lundi 10 novembre 2008
Statut
Membre
Dernière intervention
2 mars 2016
311
Modifié par xav3601 le 3/06/2010 à 10:00
Modifié par xav3601 le 3/06/2010 à 10:00
Salut,
Comment, c'est possible que ca t'écrives ca:
The constructor for this is 4/5/6
Alors que tu ne l'affiches jamais!
Ensuite, tu affiches un objet, ca peut pas marcher! Faut afficher une string...
Remplace les lignes adequates par:
birthday=theDate.toString;
Et
System.out.println(tunaObject.toString());
Et pis faut changer ta fonction toString!
La culture c'est comme la confiture, moins en a plus on l'étale!
Comment, c'est possible que ca t'écrives ca:
The constructor for this is 4/5/6
Alors que tu ne l'affiches jamais!
Ensuite, tu affiches un objet, ca peut pas marcher! Faut afficher une string...
Remplace les lignes adequates par:
birthday=theDate.toString;
Et
System.out.println(tunaObject.toString());
Et pis faut changer ta fonction toString!
La culture c'est comme la confiture, moins en a plus on l'étale!
V3n1
Messages postés
294
Date d'inscription
vendredi 30 mai 2008
Statut
Membre
Dernière intervention
12 décembre 2010
56
3 juin 2010 à 09:57
3 juin 2010 à 09:57
Je savais pas que les "%s" , "%d"... fonctionné aussi en Java.
En tout cas j'ai vraiment du mal avec ton mode de fonctionnement :S
En tout cas j'ai vraiment du mal avec ton mode de fonctionnement :S
xav3601
Messages postés
3288
Date d'inscription
lundi 10 novembre 2008
Statut
Membre
Dernière intervention
2 mars 2016
311
3 juin 2010 à 09:59
3 juin 2010 à 09:59
J'avais même pas regardé ses fonctions toString()...
Bref faut tout refaire là :S
Bref faut tout refaire là :S
3 juin 2010 à 10:49
public class Tuna
{
private String name;
private Potpie birthday;
public Tuna(String theName,Potpie theDate)
{
name=theName;
birthday=theDate.toString;
}
public String toString()
{
return String.format("My name is %s","my birthday is %s",name,birthday);
}
}
package javaapplication1;
public class Apples
{
public static void main(String[]args)
{
Potpie potObject=new Potpie (4,5,6);
Tuna tunaObject=new Tuna ("creg",potObject);
System.out.println(tunaObject.toString());
}
)
j'ai corrigé le programme comme tu m'ai dit,maintenant,il affiche les erreur suivantes:
The constructor for this is 4/5/6
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
symbol: variable toString
location: class javaapplication1.Potpie
at javaapplication1.Tuna.<init>(Tuna.java:12)
at javaapplication1.Apples.main(Apples.java:9)
3 juin 2010 à 10:54
Y'a des erreurs un peu partout!
les %s en java t'oublie par exemple!
3 juin 2010 à 10:58
voilà les codes corrigés:
package javaapplication1;
public class Potpie
{
private int month;
private int day;
private int year;
public Potpie(int m,int d,int y)
{
month=m;
day=d;
year=y;
System.out.printf("The constructor for this is %s\n",this);
}
public String toString()
{
return String.format("%d/%d/%d",month,day,year);
}
}
package javaapplication1;
public class Tuna
{
private String name;
private Potpie birthday;
public Tuna(String theName,Potpie theDate)
{
name=theName;
birthday=theDate;
}
public String toString()
{
return String.format("My name is %s,my birthday is %s",name,birthday);
}
}
package javaapplication1;
public class Apples
{
public static void main(String[]args)
{
Potpie potObject=new Potpie (4,5,6);
Tuna tunaObject=new Tuna ("Greg",potObject);
System.out.println(tunaObject);
}
)
merci beaucoup