tomi45
Messages postés13Date d'inscriptionlundi 4 janvier 2010StatutMembreDernière intervention 4 avril 2008
-
27 mars 2008 à 22:39
extraman1
Messages postés103Date d'inscriptionlundi 8 septembre 2003StatutMembreDernière intervention26 décembre 2009
-
4 avril 2008 à 21:41
bonjour , je suis actuellement en 1ere année de licence et j'ai un
projet sur lequel je suis bloqué par l'affichage suivant :Exception in
thread main java.lang.NullPointerException
tomi45
Messages postés13Date d'inscriptionlundi 4 janvier 2010StatutMembreDernière intervention 4 avril 2008 2 avril 2008 à 23:52
bonjour!
j'ai réussi a créer le projet voulu mais il me reste encore a faire l'évaluation quand il y a des parenthèses mais je ne sais vraiment pas ce qu'il faut faire.Je compte vraiment sur vous avec une extrême impatience!!!!! voici tout mon programme :
public static void evaluation (StringTokenizer e) {
Pile p = new Pile();
String op=new String("+");
String w;
String z;
int b;
int c;
int resa;
String resb;
String ope;
int som=0;
int d=1;
while (e.hasMoreTokens()) {
String i = e.nextToken();
if (estunnombre(i)) {
p.empiler(i);
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
}
else if (estunoperateur(i)) {
if (estprioritaire(i)==3) {
p.empiler(i);
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
TextWindow.printNewLine();
p.empiler(e.nextToken());
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
TextWindow.printNewLine();
w = p.sommet();
b=Integer.parseInt(w);
p.depiler();
ope = p.sommet();
p.depiler();
z = p.sommet();
c=Integer.parseInt(z);
p.depiler();
resa=calculer(c,ope,b);
resb=Integer.toString(resa);
som=som+1;
TextWindow.print("(" + som + ") ");
p.empiler(resb);
p.affichePile();
} /* fin de si estprioritaire */
else if (estprioritaire(i)==2) {
if (!(resteexpression(p))) {
p.empiler(i);
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
} /* fin !resteexpression */
else {
w = p.sommet();
b=Integer.parseInt(w);
p.depiler();
ope = p.sommet();
p.depiler();
public static void evaluation (StringTokenizer e) {
Pile p = new Pile();
String op=new String("+");
String w;
String z;
int b;
int c;
int resa;
String resb;
String ope;
int som=0;
int d=1;
String s=" ";
StringTokenizer f;
while (e.hasMoreTokens()) {
String i = e.nextToken();
if (estunnombre(i)) {
p.empiler(i);
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
}
else if (estunoperateur(i)) {
if (estprioritaire(i)==3) {
p.empiler(i);
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
TextWindow.printNewLine();
p.empiler(e.nextToken());
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
TextWindow.printNewLine();
w = p.sommet();
b=Integer.parseInt(w);
p.depiler();
ope = p.sommet();
p.depiler();
z = p.sommet();
c=Integer.parseInt(z);
p.depiler();
resa=calculer(c,ope,b);
resb=Integer.toString(resa);
som=som+1;
TextWindow.print("(" + som + ") ");
p.empiler(resb);
p.affichePile();
} /* fin de si estprioritaire */
else if (estprioritaire(i)==2) {
if (!(resteexpression(p))) {
p.empiler(i);
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
} /* fin !resteexpression */
else {
w = p.sommet();
b=Integer.parseInt(w);
p.depiler();
ope = p.sommet();
p.depiler();
@Override
public String toString() {
if (suivant!=null) { //J'ai changé ici this par suivant
return info + " " + suivant.toString(); }
else return info ; // Et ici c'est info que l'on doit envoyer
}
}
*****************************************************
Cette classe a beaucoup surtout j'ai enlevé toutes tes fonctions static car ça fesait pas trop POO
public /*static*/ void evaluation (StringTokenizer e) { // Toutes les méthodes avec static je les ai mise sans static //p new Pile();>Suppression de cette ligne
String op=new String("+");
String w;
String z;
int b;
int c;
int resa;
String resb;
String ope;
int som=0;
int d=1;
String s=" ";
StringTokenizer f;
String i;
while (e.hasMoreTokens()) {
i = e.nextToken();
if (estunnombre(i)) {
p.empiler(i);
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
} else if (estunoperateur(i)) {
if (estprioritaire(i)==3) {
p.empiler(i);
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
TextWindow.printNewLine();
p.empiler(e.nextToken());
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
TextWindow.printNewLine();
w = p.sommet();
b=Integer.parseInt(w);
p.depiler();
ope = p.sommet();
p.depiler();
z = p.sommet();
c=Integer.parseInt(z);
p.depiler();
resa=calculer(c,ope,b);
resb=Integer.toString(resa);
som=som+1;
TextWindow.print("(" + som + ") ");
p.empiler(resb);
p.affichePile();
} /* fin de si estprioritaire */
else if (estprioritaire(i)==2) {
if (!(resteexpression(p))) {
p.empiler(i);
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
i=e.nextToken();
s = ""; // il faut initialiser s à "zéro"
while(!i.equals(")")) {
s = i + " " + s; /*le gros bug de ta concaténation était le fait que tu avais oublié l'espace dans le StringTokenizer(s) plus bas ne pouvais pas marcher*/ i= e.nextToken(); /* ça tu l'avais pas mis donc le "!i.equals(")")" ne marchera jamais */
}
f =new StringTokenizer(s);
evaluation(f);
}
} /* fin de while */
while (resteexpression(p)) {
TextWindow.printNewLine();
w = p.sommet();
b=Integer.parseInt(w);
p.depiler();
ope = p.sommet();
p.depiler();
z = p.sommet();
c=Integer.parseInt(z);
p.depiler();
resa=calculer(c,ope,b);
resb=Integer.toString(resa);
p.empiler(resb);
som=som+1;
TextWindow.print("(" + som + ") ");
p.affichePile();
}
} /* fin de evaluation */
public /*static*/ boolean estunnombre(String valeur) {
tomi45
Messages postés13Date d'inscriptionlundi 4 janvier 2010StatutMembreDernière intervention 4 avril 2008 4 avril 2008 à 17:39
Bonjour,merci beaucoup pour le temps que vous avez passé a me donner un coup de main!
Alors j'ai vu une petite erreur ici : c'est s= s + " " + i;
Aussi le programme ne marche pas tout a fait bien , mais il me donne quelques idées pour continuer.
Si vous arrivé à faire marcher le programme complètement , je suis tout ouïe.
Merci