-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deck.java
50 lines (38 loc) · 989 Bytes
/
Deck.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
package exam01;
import java.util.List;
import java.util.ArrayList;
public class Deck {
List<Card> cards = new ArrayList<>();
public void insertCard(Card c) {
cards.add(c);
}
public Card earliestCard() {
if (cards.size() == 0) {
return null;
}
int lowestFace = cards.get(0).getFace();
char lowestSuit = cards.get(0).getSuit();
for (int i=1; i<cards.size(); i++) {
if (cards.get(i).getSuit() < lowestSuit) {
lowestSuit = cards.get(i).getSuit();
}
if (cards.get(i).getFace() < lowestFace) {
lowestFace = cards.get(i).getFace();
}
}
Card lowestCard = new Card(lowestFace, lowestSuit);
return lowestCard;
}
public void shiftFaces(int num) {
for (int i=0; i<cards.size(); i++) {
Card card = cards.get(i);
int newFace = card.shiftedFace(num);
char suit = card.getSuit();
Card newCard = new Card(newFace, suit);
cards.set(i, newCard);
}
}
public String toString() {
return cards.toString();
}
}