Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Need Help With returning some int numbers.

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am doing a hw assignment and I am stuck.

I have 3 files:

RollingDice2(has the main method)
PairOfDice
Die

So this is what my problem is it has to roll some dies and find some numbers so like how I have it now RollingDice rolls 2 dices and finds the sum but how the RollingDice gets it roll it must go through PairOfDice and PairOfDice must go through Die and then it should come around and return it back to RollingDice but when it gets returned I get this:



So I am not sure what this is all about.

Like In my Rollingdice2 class I make 2 objects called:

Then I would have something like this:

So now I have to roll methods in PairOfDice



Finally Die has this for roll
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Hubele:
...Die one: PairOfDice@360be0 , Die Two: PairOfDice@45a877

So I am not sure what this is all about...


You are getting this output because the class PairOfDice has not overridden the toString method. Therefore, you are getting the default toString behavior inherited from Object, which is the class name concatenated with the "at" sign and a memory location.

If you want more meaningful information, you will need to override the toString method in the PairOfDice class.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, I'm confused by this...

Since a PairOfDice has two instances of Die, don't you really want just one pair (assigned to a variable with a name that suggests a pair rather than a single die)?
[ February 27, 2006: Message edited by: marc weber ]
 
Michael Hubele
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do I?
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Hubele:
Do I?


Well, aside from the names being misleading, the way it's written above, a PairOfDice has two instances of Die, along with a separate roll method for each instance. So if die1 and die2 each point to a separate instance of PairOfDice, then when you call...

die1.roll();
die2.roll2();

...you're just rolling the first instance of Die in the pair die1, and the second instance of Die in the pair die2. So die1.two and die2.one aren't doing anything.
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic