-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
161 lines (135 loc) · 4 KB
/
Copy pathCard.java
File metadata and controls
161 lines (135 loc) · 4 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
Joseph Calise
ID#: 2380565
calise@chapman.edu
CPSC-231 Section 03
MP3A_Cards
*/
public class Card {
public static final int HEARTS = 0;
public static final int SPADES = 1;
public static final int CLUBS = 2;
public static final int DIAMONDS = 3;
public static final int JACK = 11;
public static final int QUEEN = 12;
public static final int KING = 13;
public static final int ACE = 14;
public int value;
public int suit;
public Card() {
this.value = Card.ACE;
this.suit = Card.SPADES;
}
public Card(String face, String suitSelect) {
if (face.toLowerCase().equals("jack")) {
this.value = Card.JACK;
} else if (face.toLowerCase().equals("queen")) {
this.value = Card.QUEEN;
} else if (face.toLowerCase().equals("king")) {
this.value = Card.KING;
} else {
this.value = Card.ACE;
}
if (suitSelect.toLowerCase().equals("hearts")) {
this.suit = Card.HEARTS;
} else if (suitSelect.toLowerCase().equals("spades")) {
this.suit = Card.SPADES;
} else if (suitSelect.toLowerCase().equals("clubs")) {
this.suit = Card.CLUBS;
} else {
this.suit = Card.DIAMONDS;
}
}
public Card(int number, String suitSelect) {
this.value = number;
if (suitSelect.toLowerCase().equals("hearts")) {
this.suit = Card.HEARTS;
} else if (suitSelect.toLowerCase().equals("spades")) {
this.suit = Card.SPADES;
} else if (suitSelect.toLowerCase().equals("clubs")) {
this.suit = Card.CLUBS;
} else {
this.suit = Card.DIAMONDS;
}
}
public Card(int number, int suitSelect) {
this.value = number;
this.suit = suitSelect;
}
public Card(Card card) {
this.value = card.value;
this.suit = card.suit;
}
// settors
public void setValue(int value) {
this.value = value;
}
public void setValue(String face) {
if (face.toLowerCase().equals("jack")) {
this.value = Card.JACK;
} else if (face.toLowerCase().equals("queen")) {
this.value = Card.QUEEN;
} else if (face.toLowerCase().equals("king")) {
this.value = Card.KING;
} else {
this.value = Card.ACE;
}
}
public void setSuit(int suit) {
this.suit = suit;
}
public void setSuit(String suit) {
if (suit.toLowerCase().equals("hearts")) {
this.suit = Card.HEARTS;
} else if (suit.toLowerCase().equals("spades")) {
this.suit = Card.SPADES;
} else if (suit.toLowerCase().equals("clubs")) {
this.suit = Card.CLUBS;
} else {
this.suit = Card.DIAMONDS;
}
}
// gettors
public String getSuit() {
return "" + this.suit;
}
public String getValue() {
return "" + this.value;
}
// methods
public boolean equals(Card other) {
if (!(other instanceof Card)) {
return false;
} else {
if (other.suit == this.suit && other.value == this.value) {
return true;
} else {
return false;
}
}
}
public String toString() {
String results = "";
if (this.value == 11) {
results += "Jack of ";
} else if (this.value == 12) {
results += "Queen of ";
} else if (this.value == 13) {
results += "King of ";
} else if (this.value == 14) {
results += "Ace of ";
} else {
results += "" + this.value + " of ";
}
if (this.suit == 0) {
results += "Hearts";
} else if (this.suit == 1) {
results += "Spades";
} else if (this.suit == 2) {
results += "Clubs";
} else {
results += "Diamonds";
}
return results;
}
}