// This program simulates a simplified version of European Roulette. // // DEVELOPMENT NOTES: // (These notes would not be in your program's comments. They are here // to help you understand important topics or elements of this code.) // // Notice the use of a Random object to generate random numbers, and the // fencepost nature of the main loop. Notice also that the "driver" // loop is in main, with the major work left to methods. // // The conditionals in the spinWheel method are poorly structured in this // version of the program. These will be updated in the next version. import java.util.*; public class Roulette { public static void main(String[] args) { Scanner console = new Scanner(System.in); Random rand = new Random(); int bank = 100; int max = bank; int numSpins = 0; int bet = getBet(console, bank); while (bet != 0) { bank = spinWheel(console, rand, bet, bank); System.out.println(); bet = getBet(console, bank); } } public static int getBet(Scanner console, int bank) { System.out.println("Current bank: $" + bank); System.out.print("Bet how much (0 to quit)? $"); int bet = console.nextInt(); return Math.min(bet, bank); } public static int spinWheel(Scanner console, Random rand, int bet, int bank) { System.out.print("High or low? "); String pick = console.next(); int spin = rand.nextInt(37); System.out.println("Spin: " + spin); if (spin > 18) { if (pick.equalsIgnoreCase("high")) { System.out.println("You win!"); bank += bet; } else { System.out.println("You lose. :-("); bank -= bet; } } else if (spin == 0) { System.out.println("You lose. :-("); bank -= bet; } else { // spin <= 18, but not 0 if (pick.equalsIgnoreCase("low")) { System.out.println("You win!"); bank += bet; } else { System.out.println("You lose. :-("); bank -= bet; } } return bank; } }