APCS: Elevens Project, Activity 3 & 4

4 points 

Activity 3 is "Shuffling the Cards in a Deck". Read the discussion on pages 9 - 11 on the Perfect Shuffle, the Selection Shuffle and the Efficient Selection Shuffle. You do not have to do any coding.

Activity 4, on page 13, is "Adding a Shuffle Method to the Deck Class".
Read and carry out the instructions given in Exercises 1 & 2.
In Exercise 1, be sure to implement the Efficient Selection Shuffle algorithm.
Exercise 1 says, "The shuffle method also needs to reset the value of size to indicate that all of the cards can be dealt again." I did this by creating a new private instance field 'deckSize', which I set equal to 'size' in the Deck constructor. As the program runs, 'size' gets changed but 'deckSize' does not. So at the beginning of the shuffle method, you can set 'size' equal to 'deckSize' to reset 'size'.
Try what Exercise 2 suggests, which is viewing the Deck after each swap of 2 cards. The call 'System.out.println(cards)' will do this.

 

 

Resources:
Student Guide
Deck.java
DeckTester.java

 

Links:
Elevens Project
AP Computer Science