/* Punters Lounge JAVA programming course * * Lesson45.java * * Author : Erik Datapunter * Date : 28/apr/2004 * * Calculate a series of bets based on a random numbers. * */ // import the java.util.* classes containing the Random class import java.util.*; public class Lesson45 { public static void main(String[ ] args) { // variables used double Bank = 1000; double Bet = 100; double Odds = 1.91; /* new Random object called numberx, initialised using the computers clock * using the computers clock results in a different random number being generated * each time the program is run. A fixed value will generate random numbers but always * the same random numbers. */ Random numberx = new Random(System.currentTimeMillis()); // as long as there is money in the Bank keep on betting while (Bank > 0) { // determine a winning or losing bet based on a random number int WinLose = numberx.nextInt(); System.out.println(WinLose); // calculate new bank, negative number is Lose, positive number is Win if (WinLose < 0) { Bank = Bank - Bet; System.out.println("Bank = " + Bank); } else { Bank = (Bank - Bet) + (Bet * Odds); System.out.println("Bank = " + Bank); } } } }