/* * name: T. T. Guesser */ import java.awt.*; class CS5App { public static void main(String[] s) { H.p("Welcome! Choose even or odd: "); String uc = H.nl(); // uc is the user's choice String cc = "even"; // cc is the computer's choice if ( uc.equals("even") ) // make sure the computer's { // choice is different from cc = "odd"; // the user's choice } H.p("\nAll right, now choose 1 or 2: "); int uc_int = H.ni(); // uc_int is the user's int choice int cc_int = H.randInt(1,2); // random #: 1 or 2 int sum = uc_int + cc_int; // sum holds the result H.pl(); H.pl("You chose " + uc); // print the parity choices H.pl(" I chose " + cc); H.pl(); H.pl(); H.pl("You chose " + uc_int); // print the numeric choices H.pl(" I chose " + cc_int); H.pl(); String sumType = "odd"; // sumType holds the result String if (sum % 2 == 0) // here we check to be sure it's correct sumType = "even"; // the if block is one line: no braces String winner = "I"; // winner names the winner if ( sumType.equals(uc) ) // again, we check to see if it's Ok winner = "You"; // again, the if block is one line: no braces H.pl(); H.pl("The sum (" + sum + ") was " + sumType + "."); H.pl(); H.pl( winner + " win!"); H.pl("\n"); } }