-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeckOfCards.java
53 lines (45 loc) · 1.47 KB
/
DeckOfCards.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
// Class DeckOfCards for FinalProject
// Program PlayingCards by Ray Arias
class DeckOfCards extends PileOfCards {
// Default Constructor for Class DeckOfCards
// Creates a full deck of cards in order with
// no Jokers
public DeckOfCards() {
this(0);
}
// Parameterized Constructor for Class DeckOfCards
// Creates a full deck of cards in order with
// the number of Jokers at the end of it (0, 1,
// or 2) given by the int parameter.
public DeckOfCards(int jokers) {
try {
this.makeNewDeck(jokers);
} catch (NumberOutOfRangeException noor) {
noor.printStackTrace();
}
}
// This method is the private method that
// carries out the creation of a full ordered
// deck with the number of Jokers indicated
private void makeNewDeck(int jokers) throws NumberOutOfRangeException {
if ((jokers < 0) || (jokers > 2))
throw new NumberOutOfRangeException("The value of int jokers (" + jokers
+ ") is out of range! (0, 1, or 2)");
else {
for (int suit = 0; suit < 4; suit++) {
for (int rank = 1; rank <= 13; rank++) {
Card card = new Card(rank, suit);
this.addCardToBottom(card);
}
}
if (jokers >= 1) {
Card card = new Card(2, 4);
this.addCardToBottom(card);
}
if (jokers == 2) {
Card card = new Card(1, 4);
this.addCardToBottom(card);
}
}
}
}