// file: testDeck.java in Lab 14 ==> PlayingCards ==> testing // Short program to test the Deck class // It creates a new deck of 52 cards using the default constructor, // displays the deck in mint condition, shuffles the deck, then displays it again. // A test is performed of dealTop() and dealBottom(), to make sure they are // working correctly. // Written by Dr. Van Cleave, 11/27/11 .. 11/13/13 package testing; import storage.*; import acm.program.*; public class testDeck extends ConsoleProgram { public void run() { // Create a new deck and display it Deck deck = new Deck(); print("Newly minted deck:\n"); print(deck); // set the random generator seed for the shuffle, then shuffle deck.shuffle(9); // Display the deck after the shuffle print("\n\nAfter shuffle:\n"); println(deck); // Create a new, empty deck to hold the cards to be dealt Deck hand = new Deck(0); // move top 5 cards from the deck to the hand and display for (int c = 1; c <= 5; c++) { hand.add(deck.dealTop()); } println("\nTop 5 cards: " + hand); // empty out the hand, deal 5 cards from the bottom, and display hand = new Deck(0); for (int ndx = 1; ndx <= 5; ndx++) { hand.add(deck.dealBottom()); } println("\nBottom 5 cards: " + hand); } public static void main(String args[]) { (new testDeck()).start(); } }