Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

toString

 
Ranch Hand
Posts: 33
Android Mac OS X
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to display the value of 'sum1' after doing some math with it, but i keep getting: "average: gettinganestimate.Average@5f893efe"
someone said it had to do with it being and object and to use a toString method, but that isn't working out too well; I keep getting errors within the method. I had solved the problem for like half a second before, but then i did something and it went away. Any suggestions?
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kirstie Fran wrote:
someone said it had to do with it being and object and to use a toString method, but that isn't working out too well; I keep getting errors within the method. I had solved the problem for like half a second before, but then i did something and it went away. Any suggestions?



It would help if you tell us the details of what you did -- TellTheDetails.

Henry
 
Kirstie Fran
Ranch Hand
Posts: 33
Android Mac OS X
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator






and i end up getting things like:

run:
0: 10.113957033713675 average: gettinganestimate.Average@2b86c6b2
1: 6.467450812669018 average: gettinganestimate.Average@2b86c6b2
...

Sum 2 is greater
Final averages: gettinganestimate.Average@2b86c6b2, gettinganestimate.Average@1d5ee671
BUILD SUCCESSFUL (total time: 0 seconds)
 
Henry Wong
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You didn't override the toString() method. The toString() method inherited from the Object class, just states the object class type and the identity hash code.

Henry
 
Kirstie Fran
Ranch Hand
Posts: 33
Android Mac OS X
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well one of the suggestions that netbeans gave me was to place "@override" just outside of the toString() Method, but that didn't work out to well for me. So how would i actually go about doing this? because i want the actually average to appear
 
Henry Wong
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kirstie Fran wrote:So how would i actually go about doing this? because i want the actually average to appear



Well, you need to create a valid toString() method. And in that method, you need to return a String object -- which is created from the value contained in the sum1 variable.... For that, take a look at the java.lang.Double class.

Henry
 
Kirstie Fran
Ranch Hand
Posts: 33
Android Mac OS X
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, i got that part sorted out now.
thanks!
i'm just having some issues with the "average" class
 
Marshal
Posts: 75676
354
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What went wrong when yo added @Override? Did you get a "doesn't override" compiler error? That is the whole idea of @Override; if you make a tiny spelling mistake you get a compiler error.
 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic