Advertisement
Guest User

Card

a guest
Feb 11th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1.  
  2. public class Card {
  3.     String suit;
  4.     int value;
  5.     public Card() {
  6.         suit = "Spades";
  7.         value = 1;
  8.     }
  9.     public Card(String a, int b) {
  10.         suit = a;
  11.         value = b;
  12.     }
  13.     public int getValue() {
  14.         return value;
  15.     }
  16.     public void printCard() {
  17.         //Map<Integer, String> ranks = new HashMap<>;
  18.        
  19.         System.out.println(value + " of " + suit);
  20.     }
  21. }
  22.  
  23.  
  24.  
  25. import java.util.*;
  26.  
  27. public class Deck {
  28.     ArrayList<Card> c = new ArrayList<Card>();
  29.     String suits[] = {"Spades", "Hearts", "Clubs", "Diamonds"};
  30.     Random r = new Random();
  31.    
  32.     public Deck(int amount) {
  33.         for(int i = 0; i < amount; i++) {
  34.             c.add(new Card(suits[r.nextInt(4)], r.nextInt(14)));
  35.         }
  36.     }
  37.     public void printDeck() {
  38.         for(int i = 0; i < c.size(); i++) {
  39.             c.get(i).printCard();
  40.         }
  41.     }
  42. }
  43.  
  44.  
  45.  
  46.  
  47. public class Main {
  48.     public static void main(String args[]) {
  49.         Deck deck = new Deck(5);
  50.         deck.printDeck();
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement