Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program called ShuffleDeck. This will simulate randomly shuffling a deck of cards. The cards will be represented by strings found in the file

Write a program called ShuffleDeck. This will simulate randomly shuffling a deck of cards. The cards will be represented by strings found in the file deckofcards.txt. Begin by reading these strings into a queue of strings. Call a method with the signature:

public static void shuffle(Queue deck) 

This method performs the following steps:

  • Compute a value called the shuffle count that is the base 2 log of the size of the deck
  • In a loop that executes shuffle count times:
    • Create two queues left and right
    • While the deck queue is not empty:
      • Dequeue a card from the deck
      • Flip a coin
      • If heads comes up enqueue that card on left otherwise enqueue it on right
    • Dequeue every card from left and enqueue it on deck
    • Do the same for right
  • return

Upon returning from the method, print out the deck, one card to a line.

deckofcards.txt is the following:

5_of_Clubs 6_of_Clubs 7_of_Clubs 8_of_Clubs 9_of_Clubs 10_of_Clubs Jack_of_Clubs Queen_of_Clubs King_of_Clubs Ace_of_Diamonds 2_of_Diamonds 3_of_Diamonds 4_of_Diamonds 5_of_Diamonds 6_of_Diamonds 7_of_Diamonds 8_of_Diamonds 9_of_Diamonds 10_of_Diamonds Jack_of_Diamonds Queen_of_Diamonds King_of_Diamonds Ace_of_Spades 2_of_Spades 3_of_Spades 4_of_Spades 5_of_Spades 6_of_Spades 7_of_Spades 8_of_Spades 9_of_Spades 10_of_Spades Jack_of_Spades Queen_of_Spades King_of_Spades

JAVA, PLEASE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions