• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

toString

 
Ranch Hand
Posts: 33
Android Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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: 23883
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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: 70228
282
  • Mark post as helpful
  • send pies
  • 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.
 
I didn't say it. I'm just telling you what this tiny ad said.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic