Advertisement
richarduie

CardTester2.java

Mar 31st, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. public class CardTester2
  2. {
  3.     public static void main (String args[]) {
  4.         // last index position in NAMES constant of Deck
  5.         int lastNameIdx = Deck.getNAMES().length - 1;
  6.         // last index position in SUITS constant of Deck
  7.         int lastSuitIdx = Deck.getSUITS().length - 1;
  8.  
  9.         for (int i = 0; i < 20; i++) {
  10.             // generate next name - using NAMES from Deck class assures that
  11.             // name sent to Card constructor will be valid name String for Card
  12.             String name = ( Deck.getNAMES() )[ getRandom( lastNameIdx ) ];
  13.             // generate next suit  -  using SUITS from Deck class assures that
  14.             // suit sent to Card constructor will be valid suit String for Card
  15.             String suit = ( Deck.getSUITS() )[ getRandom( lastSuitIdx ) ];
  16.             // create new card
  17.             Card card = new Card( name, suit );
  18.  
  19.             System.out.println( card.toString( ));
  20.         }
  21.     }
  22.    
  23.     public static int getRandom( int max ) {
  24.         return getRandom( 0, max );
  25.     }
  26.     public static int getRandom(int min, int max ) {
  27.         return min + (int)(Math.random() * ((max - min) + 1));
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement