/** A general driver program that uses a deck of shuffled cards. */ import java.io.*; public class Driver { public static void main(String [] args) throws IOException { // Create a shuffled deck of cards. Show all 52 cards so we can // see that they are shuffled correctly, and also to check that // we are dealing correctly later. (In a real game of course we would // not reveal all the cards like this.) Deck d = new Deck(); System.out.println("Here are all the cards:"); System.out.println(d); // Now that the cards have been shuffled, the game would continue // from here. I don't have a particular game in mind, so let's just // deal as many cards the player would like to see. BufferedReader kbd = new BufferedReader(new InputStreamReader(System.in)); System.out.print("How many cards do you want? "); int howMany = Integer.parseInt(kbd.readLine()); // This loop will draw cards. Note that by declaring i in the initializer // portion of the for loop, i can only be used in the loop and not after. // This isn't a problem here because there is nothing after the loop. for (int i = 0; i < howMany; ++i) { Card c = new Card(d.getNextCard()); System.out.println("Card # " + (i+1) + " is the " + c); } } }