Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toString

 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to make a toString to display my stack but i'm getting incompatible types. its the method starting on 106.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12181
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should line 108 be



(missing the parens)
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I sure do feel silly now thank you
 
Dustin Schreader
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
although When it prints out in gui it only prints out 1 item of the stack what I would like it to do is keep printing out the entire stack such as
4
3
2
n
t
So you can see every element in the stack, this is what i'm using in my gui to print it out at the moment.

outputStackTF.setText(myStack.toString());
 
fred rosenberger
lowercase baba
Bartender
Posts: 12181
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just barely skimmed your code, so i may not be correct. But it looks to me like in your public String toString() method, you are only calling the toString() method on the top element...therefore, it only prints what is in the top element.

What you would need to do is write some code that reads each element in the stack and calls IT'S toString() method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic