MindReaderApplet Applet

The computer will try to guess if you will say 'heads' or 'tails' You get a point if the computer is wrong, the computer will score a point if it is right. First to score 25 wins!
Your browser is ignoring the <APPLET> tag!
Roload the page to start over.
MindReaderApplet.java
SmartGuesser.java

The SmartGuesser API

public class SmartGuesser
extends java.lang.Object

SmartGuesser is a Heads/Tails Guesser that uses some basic AI. It tally's the previous four guesses to guess the next user response Based on Nifty Assignment by Raja Sooriamurthi, which itself is based on work by Gregory Rawlins, both at Indiana U. Bloomington

Version:
21 Oct 2007
Author:
Chris Thiel, OFMCap

Field Summary
 java.lang.String HEADS
           
 java.lang.String TAILS
           
 
Constructor Summary
SmartGuesser()
          Constructor for objects of class HTCounter
 
Method Summary
 int getHeadCount()
          number of head given the same combination of the last 4 user choices
 int getTailCount()
          number of tails given the same combination of the last 4 user choices
 java.lang.String makeGuess()
          sends a "h" or a "t" as the prediction of the next user guess
 void updateHistory(java.lang.String guess)
          record the last choice with the appropriate history
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Minder Read Console API

public class MindReaderApp
extends java.lang.Object


Field Summary
static int myScore
           
static double percentCorrect
           
static int userScore
           
 
Constructor Summary
MindReaderApp()
           
 
Method Summary
static java.lang.String getUserChoice()
          keep promting user until they type either an "h" or a "t"
static void init()
          initialize values
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myScore

public static int myScore

percentCorrect

public static double percentCorrect

userScore

public static int userScore

MindReaderApp.java

        
        
/**
 * MindReader Console Driver
 * 
 * Makes a Prediction...Asks for Head/Tails. 
 * Reveals if correctly predicted and keeps score
 * 
 * Based on Nifty Assignment by Raja Sooriamurthi, which itself
 * is based on work by Gregory Rawlins, both at Indiana U.
 * 
 * @author Chris Thiel, OFMCap
 * @version 21 Oct 2007
 */
import java.util.Scanner;
public class MindReaderApp
{
    // instance variables - replace the example below with your own
    public static int userScore;
    public static int myScore;
    public static double percentCorrect;
    private static String choice;
    private static String prediction;
    private static SmartGuesser hal;
    private static Scanner keyboard;
    
    /**
     * initialize values
     */
    public static void init()
    {
        // initialise instance variables
        hal = new SmartGuesser();
        userScore = 0;
        myScore =0;
        choice="";
        keyboard=new Scanner(System.in);
        System.out.println("MindReader:  I will try to guess if you say 'heads' or 'tails'");
        System.out.println("You get a point if I'm wrong, I get a point if I'm right");
        System.out.println("First to score 25 wins");
    }
    /**
     * keep promting user until they type either an "h" or a "t"
     * @return either an "h" or a "t"
     */
    public static String getUserChoice()
    {
        String choice="";
        do
        {
            System.out.println("I have predicted your choice");
            System.out.print("What is your choice [h/t]: ");
            choice = keyboard.nextLine();
        } while (?????????????????????); while the user refuses to type a "h" or a "t"
         return choice;
    }
    public static void main (String[] args)
    {
        init();
        
        while (???????????????????????) //while no one reached 25 yet
        {
            prediction=hal.makeGuess();   
            System.out.println("I have predicted your choice");
            System.out.print("What is your choice [h/t]: ");
            choice=getUserChoice();
            System.out.println("You guessed "+choice+
                             "--I predicted you would say "+prediction);
            if (choice.equals(prediction)) myScore++; else userScore++;
            hal.updateHistory(choice);
            System.out.println("Score:   You:"+userScore+"  Me: "+myScore);
        }
        if (myScore>userScore) System.out.println("I WIN"); 
          else System.out.println("YOU WIN");
    }

    
}