Results 1 to 2 of 2
Thread: Adding things to a queue
- 03-03-2013, 05:06 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 22
- Rep Power
- 0
Adding things to a queue
As English is not my first language, i sometimes have trouble understanding a teacher's instructions as to what she wants. I will be providing the instruction of what she wants, the code i made, and my problem.
Instruction: • Has a private method to “shuffle” that creates a Queue with the 52 cards randomly shuffled. Use the Random Class.
My Code:
Problem: Am i following my teacher's instruction correctly for what she wants? And if i am, my problem is, i have created a queue, but how do i make it with the 52 cards randomly shuffled? i just cant figure out the code that would make the queue with the 52 cards shuffled. i have the shuffling part down i think. Any help would be appreciated.Java Code:private static Queue<String> Deck = new LinkedList<String>(); private void shuffling() { Random generator = new Random(); int[] cards = new int[52]; for (int i=0; i<cards.length; i++) { cards[i] = i; } for (int i=0; i<cards.length; i++) { int randomPosition = generator.nextInt(cards.length); int temp = cards[i]; cards[i] = cards[randomPosition]; cards[randomPosition] = temp; } }
With regards,
A novice programmer
- 03-04-2013, 04:03 AM #2
Senior Member
- Join Date
- Jan 2013
- Location
- United States
- Posts
- 902
- Rep Power
- 1
Re: Adding things to a queue
Well, you are shuffling the cards but some cards may still be in their original position (which is also true of an actual shuffle). You could always put them in a queue after the fact (if that is what she expects). Have you discussed the Queue class in her class? Does she expect you to use part of the Collections API? You really should take your code and discuss it with her. That is what she is there for.
Regards,
JimThe Java™ Tutorial
YAT -- Yet Another Typo
Similar Threads
-
Need help with GUI and integers(just some basic things)
By Wizard0860 in forum New To JavaReplies: 1Last Post: 12-14-2012, 09:50 PM -
Servlet, Glassfish JMS java.lang.IllegalArgumentException: MQ:Queue:Invalid Queue Nam
By akasozi in forum Java ServletReplies: 0Last Post: 05-27-2011, 08:46 AM -
Need Help. with two simple things
By Fred1 in forum New To JavaReplies: 32Last Post: 04-28-2011, 02:35 AM -
XML, and other things.
By Tortex in forum New To JavaReplies: 5Last Post: 03-28-2010, 05:53 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks