/* Punters Lounge JAVA programming course * * Lesson55.java * * Author : Erik Datapunter * Date : 28/apr/2004 * * Passing arguments to a program. * * Warning : program requires 4 parameters , all being of the Integer type * * eg. C:\JAVA>JAVA Lesson55 1000 100 3 1 * */ public class Lesson55 { public static void main(String[ ] arguments) { // Array to contain the arguments passed in int[] ProgramData = new int[4]; // variable names used to access the info in the Array int Bank = 0; int Bet = 1; int Odds = 2; int WinLose = 3; // convert the String information of the arguments into integer and store in our array ProgramData[Bank] = Integer.parseInt(arguments[ Bank ]); ProgramData[Bet] = Integer.parseInt(arguments[ Bet ]); ProgramData[Odds] = Integer.parseInt(arguments[ Odds ]); ProgramData[WinLose] = Integer.parseInt(arguments[ WinLose ]); // calculate new bank if (ProgramData[WinLose] == 0) { ProgramData[Bank] = ProgramData[Bank] - ProgramData[Bet]; } else { ProgramData[Bank] = (ProgramData[Bank] - ProgramData[Bet]) + (ProgramData[Bet] * ProgramData[Odds]); } System.out.println(ProgramData[Bank]); } }