|
-
September 19th, 2008, 04:39 AM
#1
Stuck on assignment (due soon)
We're making a sort of yahtzee-type dice game.
There are two classes, Die, and Dice. Dice serves as a collection and means of manipulating multiple Die at a time.
The class for the dice is relatively simple and unimportant at the moment storing a 'size' value, a 'value' value, along with set, get, and roll methods.
In the 'Dice' Class, I add desired Die into an ArrayList, as I was told to.
Adding Die to this list is not difficult.
However, I am also to be able to add Die from a and existing 'Dice' object.
Here's what I've got so far.
...
public void add( Die dieToAdd )
{
diceArray.add( dieToAdd );
}
...
This part seems to work fine. (I've already declared the ArrayList a while back.)
Now here is where I get problems.
...
public void add( Dice diceToAdd )
{
Collections.copy(diceToAdd.diceArray,this.diceArray);
}
...
Why this does not work is beyond me. Please help. Much appreciated.
-
September 19th, 2008, 06:41 AM
#2
Re: Stuck on assignment (due soon)
Are there error messages? Please copy and paste them here. The text of the message will say what's wrong.
Norm
-
September 19th, 2008, 11:41 AM
#3
Re: Stuck on assignment (due soon)
The question is too generic. Please, post the error message at least. It would be perfect if you attach both of your classes as well tho.
Wanna install linux on a vacuum cleaner. Could anyone tell me which distro sucks better?
I had a nightmare last night. I was dreaming that I’m 64-bit and my blanket is 32-bit and I couldn’t cover myself with it, so I’ve spent the whole night freezing. And in the morning I find that my blanket just had fallen off the bed. =S (from: bash.org.ru)
//always looking for job opportunities in AU/NZ/US/CA/Europe :P
willCodeForFood(Arrays.asList("Java","PHP","C++","bash","Assembler","XML","XHTML","CSS","JS","PL/SQL"));
USE [code] TAGS! Read this FAQ if you are new here. If this post was helpful, please rate it!
-
September 19th, 2008, 09:42 PM
#4
Re: Stuck on assignment (due soon)
you'd better put your full source code here. So that we can see the exact problem.
---------------------------------------
www.codeuu.com
-
September 21st, 2008, 04:37 AM
#5
Re: Stuck on assignment (due soon)
 Originally Posted by nimm02
Why this does not work is beyond me.
And what doesn't work is beyond everybody else.
Maybe the problem is that Collections.copy doesn't make a deep copy, only a shallow one. This means that no actual copies of the Dice objects are created when they're copied to the new ArrayList. Only the references to the objects are copied, not the objects themselves. After the copy you have two ArrayLists referencing the same objects.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|