Advertisement
richarduie

Card.java

Mar 31st, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. /*
  2.  * Card holds minimal data to define state of a single card
  3.  * in a Deck and public accessors to its private fields.
  4.  */
  5.  
  6. public class Card
  7. {
  8.     // instance variables
  9.     private String name;
  10.     private String suit;
  11.  
  12.     private Deck myDeck = new Deck();
  13.    
  14.     // default constructor
  15.     public Card() {
  16.         this( "Ace", "Spades" );
  17.     }
  18.     // constructor
  19.     public Card(String n, String s) {
  20.         name = n;
  21.         suit = s;
  22.     }
  23.  
  24.     // accessors
  25.     public int getPointValue() {
  26.         Integer point = (Integer) myDeck.getCARDS( ).get( name + " of " + suit );
  27.         return (null == point) ? -999 : point.intValue();
  28.     }
  29.     public String getName() {
  30.         return name;
  31.     }
  32.     public String getSuit() {
  33.         return suit;
  34.     }
  35.  
  36.     public String toString() {
  37.         return name + " of " + suit + " - worth " +
  38.             getPointValue() + " points";
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement