Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Random;
- import java.util.Scanner;
- /*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.*/
- public class Main2 {
- public static final Scanner SC = new Scanner(System.in);
- public static int rounds = 10;
- public static int balance = 50;
- public static Random random = new Random();
- public static String choose;
- public static int bet;
- public static int counter;
- public static void main(String[] args) {
- win();
- }
- public static ArrayList fruits() {
- String[] fruitTab = {"pomarancz", "pomarancz", "pomarancz", "truskawka", "malina", "truskawka", "pomarancz", "pomarancz", "pomarancz", "truskawka"};
- ArrayList listOfFruit = new ArrayList<String>();
- for (int i = 0; i < 4; i++) {
- listOfFruit.add(fruitTab[random.nextInt(10)]);
- }
- return listOfFruit;
- }
- public static void win() {
- do {
- inputFromUser();
- counter = 0;
- for (int i = 0; i < 4; i++) {
- System.out.println(fruits().get(i));
- if (fruits().get(i).equals(choose)) {
- counter++;
- }
- }
- System.out.println(counter);
- if (counter > 2) {
- System.out.println("Congratulations, you won!");
- balance = bet * 100;
- System.out.println("balance: " + balance);
- }
- if (counter < 2) {
- balance -= bet;
- System.out.println("balance: " + balance);
- }
- rounds--;
- System.out.println("Rounds left: " + rounds);
- } while (rounds > 0 && balance > 0);
- System.out.println("looser");
- }
- public static void inputFromUser() {
- System.out.println("what's your choice? ");
- choose = SC.next();
- System.out.println("what's your bet? ");
- bet = SC.nextInt();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement