// This program simulates a simplified version of European Roulette // in which the player always bets the same amount and always bets // on "low." // // Notice the use of Random objects, the tallying of the number of // spins, and the tracking of the maximum bank. import java.util.*; public class Roulette { public static final int BET = 15; public static void main(String[] args) { Random r = new Random(); int bank = 100; int max = bank; int numSpins = 0; while (bank > 0) { System.out.println("You have $" + bank + " remaining."); int bet = Math.min(bank, BET); int spin = r.nextInt(37); System.out.println("Spin was: " + spin); if (spin <= 18 && spin != 0) { System.out.println("You win!"); bank += bet; } else { // spin > 18 || spin == 0 System.out.println("You lose. :-("); bank -= bet; } if (bank > max) { max = bank; } numSpins++; } System.out.println("Spun " + numSpins + " times, Max bank = $" + max); } }