Advertisement
FADEDxLIGHTNING

4.6

Nov 30th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1. //Cards Class
  2. import java.util.*;
  3. public class Cards {
  4.     public enum Rank { DEUCE(2), THREE(3), FOUR(4), FIVE(5), SIX(6),
  5.         SEVEN(7), EIGHT(8), NINE(9), TEN(10), JACK(10), QUEEN(10), KING(10), ACE(11);
  6.  
  7.         private int Rankpoints;
  8.  
  9.  
  10.         private Rank(int points)
  11.         {
  12.         this.Rankpoints = points;  
  13.         }
  14.  
  15.         public int getRankpoints()
  16.         {
  17.         return Rankpoints;
  18.         }
  19.  
  20.  
  21.         }
  22.  
  23.         public enum Suit { CLUBS(2), DIAMONDS(3), HEARTS(4), SPADES(1);
  24.  
  25.         private int Suitpoints;
  26.  
  27.         Suit(int points)
  28.         {
  29.  
  30.         Suitpoints = points;  
  31.  
  32.         }
  33.  
  34.  
  35.  
  36.         public int getSuitpoints()
  37.         {
  38.         return Suitpoints;
  39.         }
  40.  
  41.         }
  42.  
  43.  
  44.  
  45.         private final Rank rank;
  46.         private final Suit suit;
  47.  
  48.         private Cards(Rank rank, Suit suit)
  49.         {
  50.         this.rank = rank;
  51.         this.suit = suit;
  52.         }
  53.  
  54.  
  55.  
  56.         public Rank rank()
  57.         {
  58.         return this.rank;
  59.         }
  60.         public Suit suit()
  61.         {
  62.  
  63.         return this.suit;
  64.  
  65.         }
  66.  
  67.         public String toString()
  68.         {
  69.         return rank + " of " + suit;
  70.         }
  71.  
  72.         private static final List<Cards> protoDeck = new ArrayList<Cards>();
  73.  
  74.         // Initialize prototype deck
  75.         static {
  76.         for (Suit suit : Suit.values())
  77.             for (Rank rank : Rank.values())
  78.                 protoDeck.add(new Cards(rank, suit));
  79.  
  80.         }
  81.  
  82.         public static ArrayList<Cards> newDeck()
  83.         {
  84.  
  85.         return new ArrayList<Cards>(protoDeck); // Return copy of prototype deck
  86.         }
  87. }
  88.  
  89. //Deal Class
  90. import java.util.*;
  91. public class Deal {
  92.     public static void main(String args[])
  93.     {
  94.         int numHands = 1;
  95.         int cardsPerHand = 20;
  96.         List<Cards> deck  = Cards.newDeck();
  97.         Collections.shuffle(deck);
  98.         int total = 0;
  99.         ArrayList<Cards> hand = new ArrayList<Cards>();
  100.  
  101.  
  102.  
  103.    
  104.  
  105.  
  106.  
  107.         for (int i=0; i < numHands; i++)
  108.             System.out.println(deal(deck, cardsPerHand));   // prints the hand
  109.            //deal(deck,cardsPerHand,numHands);
  110.     }
  111.  
  112.  
  113.     // hand
  114.      public static ArrayList<Cards> deal(List<Cards> deck, int n) {
  115.          int deckSize = deck.size();
  116.          List<Cards> handView = deck.subList(deckSize-n, deckSize);
  117.          ArrayList<Cards> hand = new ArrayList<Cards>(handView);
  118.          handView.clear();
  119.       // Map<String, Map<String, Integer>> inputWords = new HashMap<String, Map<String, Integer>>();
  120.          
  121.  
  122.           return hand;
  123.         }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement