Results 1 to 2 of 2
  1. #1
    prabhdsun is offline Member
    Join Date
    Dec 2012
    Posts
    22
    Rep Power
    0

    Default 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:
    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;
            }
        }
    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.

    With regards,

    A novice programmer

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,039
    Rep Power
    6

    Default 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,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Need help with GUI and integers(just some basic things)
    By Wizard0860 in forum New To Java
    Replies: 1
    Last Post: 12-14-2012, 10:50 PM
  2. Replies: 0
    Last Post: 05-27-2011, 09:46 AM
  3. Need Help. with two simple things
    By Fred1 in forum New To Java
    Replies: 32
    Last Post: 04-28-2011, 03:35 AM
  4. XML, and other things.
    By Tortex in forum New To Java
    Replies: 5
    Last Post: 03-28-2010, 06:53 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •