Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.19 KB | None | 0 0
  1. package assessment.pkg1.p2;
  2.  
  3. import java.util.Scanner;
  4. import java.util.Random;
  5.  
  6.  //@author Brent Daya 17982253
  7.  
  8. public class SlotMachine {
  9.     private Random generator;
  10.     private int tokenCredit;
  11.    
  12.     public SlotMachine()
  13.     {
  14.            this.generator = new Random();
  15.            this.tokenCredit = 0;
  16.        }
  17.     public void topupTokens(int tokens)
  18.     {
  19.         this.tokenCredit += tokens;
  20.        
  21.     }
  22.     public int cashoutTokens()
  23.     {
  24.        
  25.        int cashoutTokens = this.tokenCredit;
  26.        this.tokenCredit = 0;
  27.      
  28.         return cashoutTokens;
  29.     }
  30.     public void pullLever(){
  31.         pullLever(1);
  32.     }
  33.     public void pullLever(int tokenInput)
  34.     {
  35.         if (tokenInput > tokenCredit)
  36.         {
  37.             System.out.println("Insufficient Token Balance");
  38.             return;
  39.         }
  40.         tokenCredit -= tokenInput;
  41.        
  42.         int slot1 = generator.nextInt(9);
  43.         int slot2 = generator.nextInt(9);
  44.         int slot3 = generator.nextInt(9);
  45.        
  46.         System.out.println("{"+slot1+","+slot2+","+slot3+"}");
  47.        
  48.         if (slot1 == 0 &  slot2 == 0 & slot3 == 0)
  49.         {
  50.             this.topupTokens(tokenInput * 500);
  51.             System.out.println("Super Jackpot Winner");
  52.         }
  53.         else if (slot1 == slot2 && slot2 == slot3)
  54.         {
  55.             System.out.println("Jackpot Winner");
  56.             this.topupTokens(tokenInput * 50);
  57.         }
  58.         else if (slot1 == slot2 || slot1 == slot3 || slot2 == slot3)
  59.         {
  60.             System.out.println("Free Spin");
  61.             this.topupTokens(tokenInput);
  62.         }
  63.         else
  64.         {
  65.             System.out.println("Bad Luck, Try again");
  66.         }
  67.  
  68.     }
  69.     public int getTokenBalance()
  70.     {
  71.         return tokenCredit;
  72.     }
  73.    
  74.     private static int houseCredit;
  75.    
  76.     public static void main(String args[])
  77.     {
  78.        Scanner scanner = new Scanner(System.in);
  79.        
  80.        System.out.println("Enter amount of Tokens: ");
  81.        int userInput = scanner.nextInt();
  82.        
  83.        SlotMachine slotMachine = new SlotMachine();
  84.        slotMachine.topupTokens(userInput);
  85.        
  86.        System.out.println("Current Tokens: "+slotMachine.getTokenBalance()+" ");
  87.        
  88.        houseCredit += userInput;
  89.        
  90.        boolean playAgain = true;
  91.        while (playAgain)
  92.        {
  93.            System.out.println("Type anything to continue or q to quit");
  94.            
  95.            String userInput1 = scanner.next();
  96.            if (userInput1.equals("q")) {
  97.                System.out.println("Cashing out " + slotMachine.getTokenBalance() + " tokens.");
  98.                slotMachine.cashoutTokens();
  99.                System.out.println("Leaving machine.");
  100.                System.out.println("Thank You and Good bye :)");
  101.                playAgain = false;
  102.            }
  103.            else
  104.            {
  105.                System.out.println("Enter tokens to gamble and pull the lever: ");
  106.            int tokensToPull = scanner.nextInt();
  107.            slotMachine.pullLever(tokensToPull);
  108.            
  109.            System.out.println("Current Tokens: "+slotMachine.getTokenBalance()+" ");
  110.            }
  111.        }
  112.        
  113.     }
  114.    
  115.    
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement