MCPcopy Create free account
hub / github.com/careercup/ctci / Card

Class Card

java/Chapter 8/Question8_1/Card.java:3–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1package Question8_1;
2
3public abstract class Card {
4 private boolean available = true;
5
6 /* number or face that's on card - a number 2 through 10,
7 * or 11 for Jack, 12 for Queen, 13 for King, or 1 for Ace
8 */
9 protected int faceValue;
10 protected Suit suit;
11
12 public Card(int c, Suit s) {
13 faceValue = c;
14 suit = s;
15 }
16
17 public abstract int value();
18
19 public Suit suit() {
20 return suit;
21 }
22
23 /* returns whether or not the card is available to be given out to someone */
24 public boolean isAvailable() {
25 return available;
26 }
27
28 public void markUnavailable() {
29 available = false;
30 }
31
32 public void markAvailable() {
33 available = true;
34 }
35
36 public void print() {
37 String[] faceValues = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
38 System.out.print(faceValues[faceValue - 1]);
39 switch (suit) {
40 case Club:
41 System.out.print("c");
42 break;
43 case Heart:
44 System.out.print("h");
45 break;
46 case Diamond:
47 System.out.print("d");
48 break;
49 case Spade:
50 System.out.print("s");
51 break;
52 }
53 System.out.print(" ");
54 }
55}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected