Skip to content

Feat: Adds Shawn Dunsmore Jr Lesson 16 SlotMachine.java and SlotMachineTest.java #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ public double getSalary() {
public void setSalary(double salary) {
this.salary = salary;
}

public String getDetails() {
return "ID: " + id + ", Name: " + name + ", Department: " + department + ", Salary: " + salary;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codedifferently.lesson15;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

Expand All @@ -16,4 +17,74 @@ public void testGetGreeting() {
// Act
Lesson15.main(null);
}

@Test
public void testEmployeeId_Exists() {
Employee employee = new Employee(0, null, null, 0);
assertEquals(0, employee.getId());
}

@Test
public void testEmployeeName_Exists() {
Employee employee = new Employee(0, "dave", null, 0);
assertEquals("dave", employee.getName());
}

@Test
public void testEmployeeDepartment_Exists() {
Employee employee = new Employee(0, "dave", "IT", 0);
assertEquals("IT", employee.getDepartment());
}

@Test
public void testEmployeeSalary_Exists() {
Employee employee = new Employee(0, "dave", "IT", 10000);
assertEquals(10000, employee.getSalary());
}

@Test
public void testGetEmployee() {
Employee employee = new Employee(10, null, null, 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);
assertEquals(employee, manager.getEmployee(10));
}

@Test
public void testGetEmployeeCount() {
Employee employee = new Employee(10, null, null, 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);
assertEquals(1, manager.getEmployeeCount());
}

@Test
public void testGetEmployeeUpate() {
Employee employee2 = new Employee(10, "BillyBobJenkins", null, 0);
Employee employee = new Employee(10, "Dave", null, 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);
manager.updateEmployee(employee2);

assertEquals(employee2, manager.getEmployee(10));
}

@Test
public void testGetEmployeeRemove() {
Employee employee2 = new Employee(10, "BillyBobJenkins", null, 0);
Employee employee = new Employee(11, "Dave", null, 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);
manager.addEmployee(employee2);
manager.removeEmployee(10);

assertEquals(1, manager.getEmployeeCount());
}

@Test
public void testGetDetails() {
Employee employee2 = new Employee(10, "BillyBobJenkins", "IT", 10);
assertEquals(
"ID: 10, Name: BillyBobJenkins, Department: IT, Salary: 10.0", employee2.getDetails());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.codedifferently.lesson16.ShawnDunsmore;

public enum BuyType {
BONUS_BUY,
DOUBLE_CHANCE,
NORMAL_BUY,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.codedifferently.lesson16.ShawnDunsmore;

public class InvalidPayAmountException extends Exception {

public InvalidPayAmountException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.codedifferently.lesson16.ShawnDunsmore;

import java.util.ArrayList;
import java.util.Collections;

public class SlotMachine {
private int numOfSlots;
private int payAmount;
private String name;
private BuyType buyType;
private ArrayList<String> iconList;
private int moneyNeeded;

public SlotMachine(
int numOfSlots,
int payAmount,
String name,
BuyType buyType,
ArrayList<String> iconList,
int moneyNeeded) {
this.numOfSlots = numOfSlots;
this.payAmount = payAmount;
this.name = name;
this.buyType = buyType;
this.iconList = iconList;
this.moneyNeeded = moneyNeeded;
}

public int getNumOfSlots() {
return numOfSlots;
}

public int getPayAmount() {
return payAmount;
}
public String getName() {
return name;
}

public BuyType getBuyType() {
return buyType;
}

public ArrayList<String> getIconList() {
return iconList;
}


public int payOut() {
if (buyType.equals(BuyType.DOUBLE_CHANCE)) {
return payAmount * 2;
}

if (buyType.equals(BuyType.BONUS_BUY)) {
return payAmount * 3;
}
return payAmount;
}

public ArrayList<String> spin(int money) throws InvalidPayAmountException {
if (money < moneyNeeded) {
throw new InvalidPayAmountException("Amount inavalid");
}
Collections.shuffle(iconList);
return iconList;
}

public ArrayList<String> spin(int money, int numOfSpins) throws InvalidPayAmountException {
if (money < moneyNeeded) {
throw new InvalidPayAmountException("Amount inavalid");
}
for (int i = 0; i < numOfSpins; i++) {
Collections.shuffle(iconList);
}

return iconList;
}

public int getMoneyNeeded() {
return moneyNeeded;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.codedifferently.lesson16;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.codedifferently.lesson16.ShawnDunsmore;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.ArrayList;
import org.junit.jupiter.api.Test;

public class SlotMachineTest {
@Test
public void testMoney_Exists() {
SlotMachine slot = new SlotMachine(0, 0, null, null, null, 10);
assertEquals(10, slot.getMoneyNeeded());
}

@Test
public void testNumOfSlots_Exists() {
SlotMachine slot = new SlotMachine(1, 0, null, null, null, 10);
assertEquals(1, slot.getNumOfSlots());
}

@Test
public void testNameOfSlot_Exists() {
SlotMachine slot = new SlotMachine(1, 0, "Goldie", null, null, 10);
assertEquals("Goldie", slot.getName());
}

@Test
public void testPayAmount_Exists() {
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
assertEquals(10, slot.getPayAmount());
}

@Test
public void testBuyType_Exists() {
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
assertEquals(null, slot.getBuyType());
}

@Test
public void testUseDoubleSlots() {
SlotMachine slottwo = new SlotMachine(1, 10, "Goldie", null, null, 10);
SlotMachine slotone = new SlotMachine(1, 10, "Diamond", null, null, 10);
assertEquals(1, slotone.getNumOfSlots());
assertEquals(1, slottwo.getNumOfSlots());
}

@Test
public void testSlotSpin() {
SlotMachine slot = new SlotMachine(1, 10, "Goldie", null, null, 10);
assertEquals(null, slot.getIconList());
}

@Test
public void testPayOut() {

ArrayList<String> icons = new ArrayList<>();
SlotMachine slotMachine1 =
new SlotMachine(1, 10, "Test Slot 1", BuyType.DOUBLE_CHANCE, icons, 10);
assertEquals(20, slotMachine1.payOut(), "Expected payout for DOUBLE_CHANCE to be 20");

SlotMachine slotMachine2 = new SlotMachine(1, 10, "Test Slot 2", BuyType.BONUS_BUY, icons, 10);
assertEquals(30, slotMachine2.payOut(), "Expected payout for BONUS_BUY to be 30");
}
}
Loading