HarrJ

Day 12 slots

Aug 13th, 2023 (edited)
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. package week3;
  2. import java.util.Scanner;
  3.  
  4. public class Day12B {
  5.     public static void main(String[] args) {
  6.         Scanner sc = new Scanner(System.in);
  7.         int credits = 1000;
  8.         int betAmount = 20;
  9.         String betCode = "a";
  10.         int numA,numB,numC;
  11.        
  12.         System.out.println("Current credits: " + credits);
  13.         System.out.print("A = 20, S = 50, D = 100, X = end:");
  14.         betCode = sc.nextLine();
  15.            
  16.         while (!betCode.equalsIgnoreCase("x") && credits > 0) {
  17.             // && condition to end if no credits left
  18.            
  19.             switch (betCode.toLowerCase()) {
  20.                 case "a":
  21.                     betAmount = 20;
  22.                     break;
  23.                 case "s":
  24.                     betAmount = 50;
  25.                     break;
  26.                 case "d":
  27.                     betAmount = 100;
  28.                     break;
  29.                 default:
  30.                     betAmount = 0;
  31.             }
  32.            
  33.             numA = (int) Math.round(Math.random()*6)+1;
  34.             numB = (int) Math.round(Math.random()*6)+1;
  35.             numC = (int) Math.round(Math.random()*6)+1;
  36.            
  37.             System.out.println("| " + numA + " | " + numB + " | " + numC+ " |");
  38.            
  39.             credits -= betAmount;
  40.             if (numA == numB && numB== numC) {
  41.                 System.out.println("3 of a kind"); // + 3 * betAmount
  42.                 credits += betAmount *3;
  43.             } else if (numA == numB || numB == numC || numA == numC) {
  44.                 System.out.println("2 of a kind"); // + betAmount
  45.                 credits += betAmount;
  46.             } else {
  47.                 System.err.println("Too bad. You can try again");
  48.             }
  49.            
  50.             System.out.println("Current Credits: " + credits);
  51.             System.out.print("To continue A,S,D = bet, X = end:");
  52.             betCode = sc.nextLine();
  53.         }
  54.     }
  55. }
  56.  
Add Comment
Please, Sign In to add comment