Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes check my code please? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "check my code please?" Watch "check my code please?" New topic

check my code please?

Rene Rad

Joined: Feb 10, 2010
Posts: 15
Hey everyone,

I'm writing a method to shuffle a deck and am unsure if it's executing properly. I'm not sure how to check if it is shuffling 1000 times. (using constant public static final int TIMES_TO_SHUFFLE = 1000) My instructions are in the javadoc before the code. I tried using the debugger but I kept looping in the block and am unsure how to properly use it. Here is my code...

here is the card class.

Christophe Verré

Joined: Nov 24, 2005
Posts: 14687

What I can understand from the javadoc is :
1. Take two cards (you need two random indexes)
2. Swap them (no need to use another array)
3. Repeat TIMES_TO_SHUFFLE times

If you follow these simple steps, the method should be easier to write.

[My Blog]
All roads lead to JavaRanch
Bert Wilkinson
Ranch Hand

Joined: Oct 28, 2009
Posts: 33
It looks like your instructions for the assignment are in the javadoc....

So, with that in mind, your shuffle method looks like it will do some shuffling, but it is not doing what the javadoc says it should. You are looping through the entire deck TIMES_TO_SHUFFLE times vice doing that many "swaps" within the deck. Hopefully that's clear and gives you some direction on where you need to tweak your code.

After you think you are close, you can put a println statement in there to compare the deck before and after a "shuffle" is called to convince yourself something is happening.
David Newton

Joined: Sep 29, 2008
Posts: 12617

(Consider using loop(s) in loadDeck rather than specifying each card manually, which is rather error-prone.)

Note also that "shuffling" in code is a different operation than shuffling a physical deck of cards--shuffling 1000 times is not likely to give you a deck that's (substantially?) more random than shuffling once.
I agree. Here's the link:
subject: check my code please?
Similar Threads
adding objects to an arraylist.
Compilation Err - Collection Interface Program
Urgent help PLEASE
Accessor methods on enum
How to test my code for proper function?