// Main.java // Raja Sooriamurthi public class Main { private MindReader mr; private static final int MAX = 25; // ************************* // Main // ************************* public Main() { mr = new MindReader(); } // ************************* // play // ************************* public void play () { char guess, prediction; int right = 0, wrong = 0; ConsoleReader con = new ConsoleReader( System.in ); do { System.out.println(); System.out.println ("Guess head or tails " + "and I'll predict your guess."); // 1. make a prediction prediction = mr.getPrediction(); // 2. retrieve a guess from the user System.out.print("What is your guess [h/t] ? "); guess = con.readLine().charAt(0); // 3. check if (guess == prediction) { System.out.println ("Yes :-) I too predicted " + prediction); right++; } else { System.out.println ("No :-( I predicted " + prediction); wrong++; } // 4. store the guess mr.storePlayerGuess(guess); System.out.println ("\nScore = " + right + " | " + wrong); } while ((right < MAX) && (wrong < MAX)); // print the final outcome System.out.println(); System.out.println("Final tally = " + right + " | " + wrong); System.out.println ((right > wrong) ? "I out guessed you" : "You beat me :-("); } // ************************* // main // ************************* public static void main (String[] args) { Main mn = new Main(); ConsoleReader con = new ConsoleReader( System.in ); System.out.println (" Welcome to MindReader"); do { mn.play(); System.out.print("\nPlay again [y/n] ? "); } while (con.readLine().charAt(0) =='y'); } }