-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.java
89 lines (80 loc) · 1.96 KB
/
Card.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Card.java
*
* @author: Zachary, Anand, Jason (Group 7)
* Assignment #: Blackjack Project
*
* Brief Program Description:
*
*
*/
public class Card
{
private String suit, rank;
private int numValue;
/**
* Constructor for class Card
* @param a String that indicates the suit followed by another String that indicates rank
*/
public Card(String s, String r)
{
suit = s;
rank = r;
if(r.equals("ace")) //if-else statements to determine numeric value from rank
{
numValue = 11;
}
else if(r.equals("jack") || r.equals("queen") || r.equals("king"))
{
numValue = 10;
}
else
{
numValue = Integer.parseInt(r); //converts string to int
}
}
/**
* @param NONE
* @return a String that describes the rank and suit of the card
*/
public String toString()
{
return rank+" of "+suit;
}
/**
* @param NONE
* @return an integer that represents the numeric value of the card
*/
public int getNumValue()
{
return numValue;
}
/**
* @param NONE
* @return a String that represents the suit of the card
*/
public String getSuit() //just for diagnostic purposes
{
return suit;
}
/**
* @param NONE
* @return a String that represents the rank of the card
*/
public String getRank()
{
return rank;
}
/**
* This method is invoked by the hand class
* If an ace is added to the hand, but the hand's total value
* Exceeds 21. The method changes the ace's numeric value from 11 to 1.
*/
public void setAceValue() //called by the hand class
{
if(numValue == 11) //same condition in hand -- just for double checking
{
numValue = 1;
}
}
}