Skip to content

Commit 398e46d

Browse files
committed
Intial Commit
1 parent 07df895 commit 398e46d

File tree

4 files changed

+151
-3
lines changed

4 files changed

+151
-3
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.ShawnDunsmore;
2+
3+
public enum BuyType {
4+
BONUS_BUY,
5+
DOUBLE_CHANCE,
6+
NORMAL_BUY,
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codedifferently.lesson16.ShawnDunsmore;
2+
3+
public class InvalidPayAmountException extends Exception {
4+
5+
public InvalidPayAmountException(String message) {
6+
super(message);
7+
}
8+
}
Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,106 @@
1-
package main.java.com.codedifferently.lesson16.ShawnDunsmore;
1+
package com.codedifferently.lesson16.ShawnDunsmore;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
25

36
public class SlotMachine {
4-
7+
private int numOfSlots;
8+
private int payAmount;
9+
private String name;
10+
private BuyType buyType;
11+
private ArrayList<String> iconList;
12+
private int moneyNeeded;
13+
14+
public SlotMachine(
15+
int numOfSlots,
16+
int payAmount,
17+
String name,
18+
BuyType buyType,
19+
ArrayList<String> iconList,
20+
int moneyNeeded) {
21+
this.numOfSlots = numOfSlots;
22+
this.payAmount = payAmount;
23+
this.name = name;
24+
this.buyType = buyType;
25+
this.iconList = iconList;
26+
this.moneyNeeded = moneyNeeded;
27+
}
28+
29+
public int getNumOfSlots() {
30+
return numOfSlots;
31+
}
32+
33+
public void setNumOfSlots(int numOfSlots) {
34+
this.numOfSlots = numOfSlots;
35+
}
36+
37+
public int getPayAmount() {
38+
return payAmount;
39+
}
40+
41+
public void setPayAmount(int payAmount) {
42+
this.payAmount = payAmount;
43+
}
44+
45+
public String getName() {
46+
return name;
47+
}
48+
49+
public void setName(String name) {
50+
this.name = name;
51+
}
52+
53+
public BuyType getBuyType() {
54+
return buyType;
55+
}
56+
57+
public void setBuyType(BuyType buyType) {
58+
this.buyType = buyType;
59+
}
60+
61+
public ArrayList<String> getIconList() {
62+
return iconList;
63+
}
64+
65+
public void setIconList(ArrayList<String> iconList) {
66+
this.iconList = iconList;
67+
}
68+
69+
public int payOut() {
70+
if (buyType.equals(BuyType.DOUBLE_CHANCE)) {
71+
return payAmount * 2;
72+
}
73+
74+
if (buyType.equals(BuyType.BONUS_BUY)) {
75+
return payAmount * 3;
76+
}
77+
return payAmount;
78+
}
79+
80+
public ArrayList<String> spin(int money) throws InvalidPayAmountException {
81+
if (money < moneyNeeded) {
82+
throw new InvalidPayAmountException("Amount inavalid");
83+
}
84+
Collections.shuffle(iconList);
85+
return iconList;
86+
}
87+
88+
public ArrayList<String> spin(int money, int numOfSpins) throws InvalidPayAmountException {
89+
if (money < moneyNeeded) {
90+
throw new InvalidPayAmountException("Amount inavalid");
91+
}
92+
for (int i = 0; i < numOfSpins; i++) {
93+
Collections.shuffle(iconList);
94+
}
95+
96+
return iconList;
97+
}
98+
99+
public int getMoneyNeeded() {
100+
return moneyNeeded;
101+
}
102+
103+
public void setMoneyNeeded(int moneyNeeded) {
104+
this.moneyNeeded = moneyNeeded;
105+
}
5106
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
package com.codedifferently.lesson16.ShawnDunsmore;
22

3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import org.junit.jupiter.api.Test;
5+
36
public class SlotMachineTest {
4-
7+
@Test
8+
public void testMoney_Exists() {
9+
SlotMachine slot = new SlotMachine(0, 0, null, null, null, 10);
10+
assertEquals(10, slot.getMoneyNeeded());
11+
}
12+
13+
@Test
14+
public void testNumOfSlots_Exists() {
15+
SlotMachine slot = new SlotMachine(1, 0, null, null, null, 10);
16+
assertEquals(1, slot.getNumOfSlots());
17+
}
18+
19+
@Test
20+
public void testNameOfSlot_Exists() {
21+
SlotMachine slot = new SlotMachine(1, 0, "Goldie", null, null, 10);
22+
assertEquals("Goldie", slot.getName());
23+
}
24+
25+
@Test
26+
public void testPayAmount_Exists() {
27+
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
28+
assertEquals(10, slot.getPayAmount());
29+
}
30+
31+
32+
@Test
33+
public void testBuyType_Exists() {
34+
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
35+
assertEquals(null, slot.getBuyType());
36+
}
537
}

0 commit comments

Comments
 (0)