Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Random;
  3. import java.util.Scanner;
  4.  
  5. /*3. Zaimplementuj prostą grę hazardową ‘jednoręki bandyta’, w której użytkownik podaje kwotę i gra do momentu, kiedy ma pieniądze lub 10 rund. Pojedyncza runda losuje z powtórzeniem 3 owoce ze zbioru: wiśnia (0.1), malina (0.2), truskawka (0.3), pomarańcz (0.4). Podane w nawiasie wartości SA prawdopodobieństwem losowania. Jeśli podczas rundy padły 3 takie same owoce gracz wygrał i dostaje gotówkę zgodnie z wzorem 100 / prawdopodobieństwo.*/
  6. public class Main2 {
  7. public static final Scanner SC = new Scanner(System.in);
  8. public static int rounds = 10;
  9. public static int balance = 50;
  10. public static Random random = new Random();
  11. public static String choose;
  12. public static int bet;
  13. public static int counter;
  14.  
  15. public static void main(String[] args) {
  16.  
  17.  
  18. win();
  19. }
  20.  
  21. public static ArrayList fruits() {
  22.  
  23. String[] fruitTab = {"pomarancz", "pomarancz", "pomarancz", "truskawka", "malina", "truskawka", "pomarancz", "pomarancz", "pomarancz", "truskawka"};
  24. ArrayList listOfFruit = new ArrayList<String>();
  25. for (int i = 0; i < 4; i++) {
  26. listOfFruit.add(fruitTab[random.nextInt(10)]);
  27. }
  28. return listOfFruit;
  29. }
  30.  
  31. public static void win() {
  32.  
  33. do {
  34. inputFromUser();
  35.  
  36. counter = 0;
  37. for (int i = 0; i < 4; i++) {
  38. System.out.println(fruits().get(i));
  39.  
  40. if (fruits().get(i).equals(choose)) {
  41. counter++;
  42. }
  43. }
  44. System.out.println(counter);
  45. if (counter > 2) {
  46. System.out.println("Congratulations, you won!");
  47. balance = bet * 100;
  48. System.out.println("balance: " + balance);
  49. }
  50. if (counter < 2) {
  51. balance -= bet;
  52. System.out.println("balance: " + balance);
  53. }
  54. rounds--;
  55. System.out.println("Rounds left: " + rounds);
  56.  
  57. } while (rounds > 0 && balance > 0);
  58. System.out.println("looser");
  59.  
  60. }
  61.  
  62. public static void inputFromUser() {
  63.  
  64. System.out.println("what's your choice? ");
  65. choose = SC.next();
  66.  
  67. System.out.println("what's your bet? ");
  68. bet = SC.nextInt();
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement