// Tyler Rigsby, CSE 142 // This program simulates betting on a game of roulette until all money is lost. Keeps track // of the maximum amount of money earned at any point and # of rounds played. import java.util.*; public class Roulette { public static void main(String[] args) { Random rand = new Random(); int money = 20; int count = 0; int max = money; // while we still have money while (money > 0) { int bet = 3; if (bet > money) { bet = money; } // could equivalently do: // bet = Math.min(money, 3) // spin the wheel int spin = rand.nextInt(37); if (spin != 0 && spin <= 18) { money = money + bet; } else { money = money - bet; } count++; if (money > max) { max = money; } System.out.println("Spin #" + count + ", bet=$" + bet + ", spin=" + spin + ", money now=$" + money); } System.out.println("We lost, max was $" + max); } }