Skip to content

Commit 24359c0

Browse files
committed
Added Spotless
1 parent 910c14e commit 24359c0

File tree

4 files changed

+136
-165
lines changed

4 files changed

+136
-165
lines changed
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.codedifferently.lesson16.ShawnDunsmore;
22

3-
43
public enum BuyType {
5-
BONUS_BUY,
6-
DOUBLE_CHANCE,
7-
NORMAL_BUY,
4+
BONUS_BUY,
5+
DOUBLE_CHANCE,
6+
NORMAL_BUY,
87
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.codedifferently.lesson16.ShawnDunsmore;
22

3-
43
public class InvalidPayAmountException extends Exception {
54

6-
7-
public InvalidPayAmountException(String message) {
8-
super(message);
9-
}
5+
public InvalidPayAmountException(String message) {
6+
super(message);
7+
}
108
}
Lines changed: 75 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,82 @@
11
package com.codedifferently.lesson16.ShawnDunsmore;
22

3-
43
import java.util.ArrayList;
54
import java.util.Collections;
65

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

3-
43
import static org.junit.jupiter.api.Assertions.assertEquals;
54

6-
75
import java.util.ArrayList;
86
import org.junit.jupiter.api.Test;
97

10-
118
public class SlotMachineTest {
12-
@Test
13-
public void testMoney_Exists() {
14-
SlotMachine slot = new SlotMachine(0, 0, null, null, null, 10);
15-
assertEquals(10, slot.getMoneyNeeded());
16-
}
17-
18-
19-
@Test
20-
public void testNumOfSlots_Exists() {
21-
SlotMachine slot = new SlotMachine(1, 0, null, null, null, 10);
22-
assertEquals(1, slot.getNumOfSlots());
23-
}
24-
25-
26-
@Test
27-
public void testNameOfSlot_Exists() {
28-
SlotMachine slot = new SlotMachine(1, 0, "Goldie", null, null, 10);
29-
assertEquals("Goldie", slot.getName());
30-
}
31-
32-
33-
@Test
34-
public void testPayAmount_Exists() {
35-
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
36-
assertEquals(10, slot.getPayAmount());
37-
}
38-
39-
40-
@Test
41-
public void testBuyType_Exists() {
42-
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
43-
assertEquals(null, slot.getBuyType());
44-
}
45-
46-
47-
@Test
48-
public void testUseDoubleSlots() {
49-
SlotMachine slottwo = new SlotMachine(1, 10, "Goldie", null, null, 10);
50-
SlotMachine slotone = new SlotMachine(1, 10, "Diamond", null, null, 10);
51-
assertEquals(1, slotone.getNumOfSlots());
52-
assertEquals(1, slottwo.getNumOfSlots());
53-
}
54-
55-
56-
@Test
57-
public void testSlotSpin() {
58-
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
59-
assertEquals(null, slot.getIconList());
60-
}
61-
62-
63-
@Test
64-
public void testPayOut() {
65-
66-
67-
ArrayList<String> icons = new ArrayList<>();
68-
SlotMachine slotMachine1 =
69-
new SlotMachine(1, 10, "Test Slot 1", BuyType.DOUBLE_CHANCE, icons, 10);
70-
assertEquals(20, slotMachine1.payOut(), "Expected payout for DOUBLE_CHANCE to be 20");
71-
72-
73-
SlotMachine slotMachine2 = new SlotMachine(1, 10, "Test Slot 2", BuyType.BONUS_BUY, icons, 10);
74-
assertEquals(30, slotMachine2.payOut(), "Expected payout for BONUS_BUY to be 30");
75-
}
9+
@Test
10+
public void testMoney_Exists() {
11+
SlotMachine slot = new SlotMachine(0, 0, null, null, null, 10);
12+
assertEquals(10, slot.getMoneyNeeded());
13+
}
14+
15+
@Test
16+
public void testNumOfSlots_Exists() {
17+
SlotMachine slot = new SlotMachine(1, 0, null, null, null, 10);
18+
assertEquals(1, slot.getNumOfSlots());
19+
}
20+
21+
@Test
22+
public void testNameOfSlot_Exists() {
23+
SlotMachine slot = new SlotMachine(1, 0, "Goldie", null, null, 10);
24+
assertEquals("Goldie", slot.getName());
25+
}
26+
27+
@Test
28+
public void testPayAmount_Exists() {
29+
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
30+
assertEquals(10, slot.getPayAmount());
31+
}
32+
33+
@Test
34+
public void testBuyType_Exists() {
35+
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
36+
assertEquals(null, slot.getBuyType());
37+
}
38+
39+
@Test
40+
public void testUseDoubleSlots() {
41+
SlotMachine slottwo = new SlotMachine(1, 10, "Goldie", null, null, 10);
42+
SlotMachine slotone = new SlotMachine(1, 10, "Diamond", null, null, 10);
43+
assertEquals(1, slotone.getNumOfSlots());
44+
assertEquals(1, slottwo.getNumOfSlots());
45+
}
46+
47+
@Test
48+
public void testSlotSpin() {
49+
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
50+
assertEquals(null, slot.getIconList());
51+
}
52+
53+
@Test
54+
public void testPayOut() {
55+
56+
ArrayList<String> icons = new ArrayList<>();
57+
SlotMachine slotMachine1 =
58+
new SlotMachine(1, 10, "Test Slot 1", BuyType.DOUBLE_CHANCE, icons, 10);
59+
assertEquals(20, slotMachine1.payOut(), "Expected payout for DOUBLE_CHANCE to be 20");
60+
61+
SlotMachine slotMachine2 = new SlotMachine(1, 10, "Test Slot 2", BuyType.BONUS_BUY, icons, 10);
62+
assertEquals(30, slotMachine2.payOut(), "Expected payout for BONUS_BUY to be 30");
63+
}
7664
}

0 commit comments

Comments
 (0)