Problem

Shuffling:Suppose you are developing the Card Game program suggested by Figure in the text...

Shuffling:

Suppose you are developing the Card Game program suggested by Figure in the text. The following partial UML class diagram shows where you are in the developmental process:

Assume that you have written methods for a

Card
class and a
GroupOfCards
class. Also, assume that the
addCard
method increments
currentSize
after adding the input card to the end of the currently filled part of the
cards
array. Finally, assume that the
removeCard
method retrieves a reference to the card at
index
in the
cards
array, decrements the
currentSize
of the cards array, shifts all array elements above
index
down by one place, and returns the reference to the card originally at
index
.

To shuffle the deck, use a

for
loop that starts with
unshuffled = getCurrentSize()
and steps down to one. In each iteration, use
Math.random
to pick an index in the unshuffled range, remove the card at that index, and then add it to the high end of the array. Include all that functionality in a
Deck.shuffle
method.

Extra credit:

Write Java code that tests your

shuffle
method. To do that, you’ll need to implement all of the classes and methods in the above UML class diagram. Your
main
method should instantiate a
deck,
display it, shuffle it, and display it again.

Figure Preliminary class diagram for a Card Game program

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 13
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT