/* Punters Lounge JAVA programming course * * Lesson56.java * * Author : Erik Datapunter * Date : 8/may/2004 * * Calculates a winning or losing bet, * using user input by asking questions. * */ import java.io.*; public class Lesson56 { public static void main(String[ ] arguments) throws IOException { // create a buffer to read the keyboard BufferedReader Readkeys = new BufferedReader ( new InputStreamReader (System.in)); String Response; int Bank; int Bet; int Odds; int WinLose; // ask a question and read from the keyboard System.out.println("What is the starting bank ?"); Response = Readkeys.readLine(); Bank = Integer.parseInt(Response); System.out.println("Howmuch to Stake ?"); Response = Readkeys.readLine(); Bet = Integer.parseInt(Response); System.out.println("Odds (integer) ?"); Response = Readkeys.readLine(); Odds = Integer.parseInt(Response); System.out.println("Enter 1 for a winning bet and 0 for a losing bet"); Response = Readkeys.readLine(); WinLose = Integer.parseInt(Response); // IF the bet loses if (WinLose == 0) { // bet loses, subtract Bet from Bank Bank = Bank - Bet; } else { // bet wins, subtract Bet from Bank, add return being Bet times Odds Bank = (Bank - Bet) + (Bet * Odds); } // print new Bank on the screen System.out.println("New bank = "+Bank); } }