-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPocketAL.java
More file actions
58 lines (48 loc) · 1.16 KB
/
PocketAL.java
File metadata and controls
58 lines (48 loc) · 1.16 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
import java.util.ArrayList;
/**
* A container for coins.
*
* @author Lisa Miller
* @since 9/23/2017
*/
public class PocketAL {
/** arrayList to hold the coins. */
private ArrayList<Coin> coins = new ArrayList<>();
/**
* adds a Coin to the front of the array.
* @param c the Coin to be added
*/
public void addCoin(Coin c) {
coins.add(0, c);
}
/**
* Takes out the Coin at the front of the array.
* Reduces count of Coins held.
*/
public void removeCoin() {
coins.remove(0);
}
/**
* Returns whole array of Coins.
* @return an array of Coins.
*/
public ArrayList<Coin> getCoins() {
return coins;
}
/**
* Returns how many Coins held.
* @return the number of Coins held.
*/
public int getNumCoins() {
return coins.size();
}
public static void main(String[] args) {
PocketAL myPocket = new PocketAL();
myPocket.addCoin(new Penny());
myPocket.addCoin(new Dime());
myPocket.addCoin(new Quarter());
for(int i = 0; i < myPocket.getNumCoins(); i++) {
System.out.println(myPocket.coins.get(i));
}
}
}