This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Need Help With returning some int numbers. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need Help With returning some int numbers." Watch "Need Help With returning some int numbers." New topic
Author

Need Help With returning some int numbers.

Michael Hubele
Ranch Hand

Joined: Dec 17, 2005
Posts: 182
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

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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

Joined: Dec 17, 2005
Posts: 182
Do I?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help With returning some int numbers.
 
Similar Threads
Using the equals method
Need Help Understand this.
help on Yahtzee
Variables assigned to objects
Create a Die Class