Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package assessment.pkg1.p2;
- import java.util.Scanner;
- import java.util.Random;
- //@author Brent Daya 17982253
- public class SlotMachine {
- private Random generator;
- private int tokenCredit;
- public SlotMachine()
- {
- this.generator = new Random();
- this.tokenCredit = 0;
- }
- public void topupTokens(int tokens)
- {
- this.tokenCredit += tokens;
- }
- public int cashoutTokens()
- {
- int cashoutTokens = this.tokenCredit;
- this.tokenCredit = 0;
- return cashoutTokens;
- }
- public void pullLever(){
- pullLever(1);
- }
- public void pullLever(int tokenInput)
- {
- if (tokenInput > tokenCredit)
- {
- System.out.println("Insufficient Token Balance");
- return;
- }
- tokenCredit -= tokenInput;
- int slot1 = generator.nextInt(9);
- int slot2 = generator.nextInt(9);
- int slot3 = generator.nextInt(9);
- System.out.println("{"+slot1+","+slot2+","+slot3+"}");
- if (slot1 == 0 & slot2 == 0 & slot3 == 0)
- {
- this.topupTokens(tokenInput * 500);
- System.out.println("Super Jackpot Winner");
- }
- else if (slot1 == slot2 && slot2 == slot3)
- {
- System.out.println("Jackpot Winner");
- this.topupTokens(tokenInput * 50);
- }
- else if (slot1 == slot2 || slot1 == slot3 || slot2 == slot3)
- {
- System.out.println("Free Spin");
- this.topupTokens(tokenInput);
- }
- else
- {
- System.out.println("Bad Luck, Try again");
- }
- }
- public int getTokenBalance()
- {
- return tokenCredit;
- }
- private static int houseCredit;
- public static void main(String args[])
- {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Enter amount of Tokens: ");
- int userInput = scanner.nextInt();
- SlotMachine slotMachine = new SlotMachine();
- slotMachine.topupTokens(userInput);
- System.out.println("Current Tokens: "+slotMachine.getTokenBalance()+" ");
- houseCredit += userInput;
- boolean playAgain = true;
- while (playAgain)
- {
- System.out.println("Type anything to continue or q to quit");
- String userInput1 = scanner.next();
- if (userInput1.equals("q")) {
- System.out.println("Cashing out " + slotMachine.getTokenBalance() + " tokens.");
- slotMachine.cashoutTokens();
- System.out.println("Leaving machine.");
- System.out.println("Thank You and Good bye :)");
- playAgain = false;
- }
- else
- {
- System.out.println("Enter tokens to gamble and pull the lever: ");
- int tokensToPull = scanner.nextInt();
- slotMachine.pullLever(tokensToPull);
- System.out.println("Current Tokens: "+slotMachine.getTokenBalance()+" ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement