-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardPile.java
70 lines (56 loc) · 1.39 KB
/
CardPile.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
/*
Nidhi Singh
CS 110 (Assignment #10)
CardPile Class - holds a "pile" of Cards and has methods to access them
*/
import java.util.ArrayList;
import java.util.Random;
public class CardPile
{
//uses an ArrayList of Cards to actually store cards
private ArrayList<Card> pile;
//constructor - creates the ArrayList that will be used
public CardPile()
{
pile = new ArrayList<Card>();
}
//methods
//add - puts a Card at the end ("bottom") of the pile. It just uses the ArrayList method
public void add(Card aCard)
{
pile.add(aCard);
}
//add - puts a Card at the end ("bottom") of the pile. It just uses the ArrayList method
public Card remove(int i)
{
return pile.remove(i);
}
//getTopCard - removes and returns the "top" card of the pile. It just uses the ArrayList method
public Card getTopCard()
{
return pile.remove(0);
}
//toString - returns a String representation of the pile. It just uses the ArrayList method
public String toString()
{
return pile.toString();
}
public Card get(int i)
{
return pile.get(i);
}
public Card set(int i, Card card1)
{
return pile.set(i,card1);
}
//size - returns the size of the pile. It just uses the ArrayList method
public int size()
{
return pile.size();
}
//clear - empties the pile. It just uses the ArrayList method
public void clear()
{
pile.clear();
}
}