File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help With returning some int numbers.

 
Michael Hubele
Ranch Hand
Posts: 182
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • 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
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic