/* This program shows that, unlike primitive values (int, float, etc.), class type values (Deck, Hand, etc.), can be modified inside of a method, and the result is visible back at the point of the call. WARNING: This only works if you modify the value using some method, such as the add() method for Hand or the draw() method for Deck. It does not work if you try using the assignment operator to change the value. This will all be explained when we study chapter 6. */ import tio.*; import cards.*; class CardTest2 { public static void main(String[] args) { // The deck is initialized with a random seed to randomize the cards. // You only create the deck ONCE. System.out.println("Enter the seed (enter 9 to get an ace)."); Deck deck = new Deck(Console.in.readInt()); // be sure and shuffle the deck each new hand deck.shuffle(); Hand hand = new Hand(); Hand dealerHand = new Hand(); deal(hand, deck); deal(dealerHand, deck); System.out.println("The hand is " + hand); System.out.println("The dealer hand is " + dealerHand); // DON'T DO THIS hand = new Hand(); badDeal(hand, deck); System.out.println("The hand is " + hand); } // fill the hand with 2 cards // assumes the hand was empty to start with static void deal(Hand someHand, Deck someDeck) { someHand.add(someDeck.draw()); someHand.add(someDeck.draw()); } // DON'T DO THIS. IT DOESN'T WORK! static void badDeal(Hand someHand, Deck someDeck) { someHand = new Hand(); someHand.add(someDeck.draw()); someHand.add(someDeck.draw()); } }