-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.java
53 lines (40 loc) · 971 Bytes
/
Stack.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
package solitaire;
import java.util.ArrayList;
public class Stack {
private ArrayList<Card> stack = new ArrayList<Card>();
Stack(Deck d,int i) {
Card c;
for (int j=0;j<i;j++) {
c = d.getCard();
if (j < i-1) { c.setFaceDown(); }
stack.add(c);
}
}
Stack () { }
public void add(Card c) {
stack.add(c);
}
public void remove(Card c) {
stack.remove(c);
}
public Card get(int i) {
return stack.get(i);
}
public int size() {
return stack.size();
}
public Card getTopCard() {
if (stack.size() == 0) {
return null;
}
else {
return stack.get(stack.size()-1);
}
}
public Card get2ndCard() {
return stack.get(stack.size()-2);
}
public ArrayList<Card> getStack() {
return stack;
}
}