/* * P0Main.java * * Created on January 6, 2003, 9:22 PM */ package project0; /** CSE143 03wi Project 0: "Does The God of Luck Know You?". * Driver class. Your program will be tested with this, but you won't be * able to turn in a modified version. * */ public class P0Main { /** Number of individual trials to run. 3 is chosen as being a mystical number.*/ public static final int trialsToRun = 3; /** Default value in case an argument is not supplied on the command line. */ //public static final String defaultInitials = "X"; //test value (error) //public static final String defaultInitials = "A1"; //test value (error) //public static final String defaultInitials = "ABC"; //test value (error) public static final String defaultInitials = "MD"; /** Driver program for the application; not to be changed! * This main should be invoked from the command line, with a single string argument (a string of exactly two uppercase letters); in Bluej, it can * be run directly and an argument string typed into the dialog box. */ public static void main (String[] args) { System.out.println("\nThis program will invoke the god/goddess of luck " + "and determine how well the deity knows you."); if (args.length != 1) { System.out.println("Next time, please supply exactly one argument: " + "a string of two upper case letters."); args = new String[] {defaultInitials}; //dummy up the argument array System.out.println("Continuing with the default argument " + args[0]); } String yourInitials = args[0]; System.out.println("\n" + yourInitials + ", you may enter the temple."); invokeTheGodsOfLuck(yourInitials); System.out.println("The session is over, " + yourInitials + "." + " Exit temple on the left."); //end main } private static void invokeTheGodsOfLuck(String initials) { LuckTester tester = new LuckTester(); boolean initialsAreOK = tester.checkInitials(initials); if (!initialsAreOK) { System.out.println("Violation! " + initials + " is not a suitable pair of initials. You have insulted the deities."); return; } System.out.println("O great deities of Luck, we ask you " + trialsToRun + " times: How well do you know " + initials + "?"); int trialsSum = 0; //total number of invocations (trials) so far for (int t = 1; t <= trialsToRun; t++) { int result = tester.tryUntilSuccess(initials); System.out.println("Trial #:" + t + " " + result + " pairs before success, implying " + tester.interpret(result)); trialsSum += result; } double averageResult = ((double) trialsSum) / trialsToRun; String resultEvaluation = tester.interpret(averageResult); System.out.println("\n Overall evaluation after " + trialsToRun + " trials: " + averageResult + ". The message is clear:\n " + resultEvaluation); //end invokeTheGodsOfLuck } }