/* Punters Lounge JAVA programming course * * Lesson44.java * * Author : Erik Datapunter * Date : 28/apr/2004 * * Calculate a bet based on a random number. * */ // import the java.util.* classes containing the Random class import java.util.*; public class Lesson44 { public static void main(String[ ] args) { // variables used int Bank = 1000; int Bet = 100; int Odds = 3; /* 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()); // generate a random number to determine a winning or losing bet 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; } else { Bank = (Bank - Bet) + (Bet * Odds); } System.out.println(Bank); } }