Assignment 44; TwentyQuestions
Code
// Donovan Rich
// Period 6
// Twenty Questions... well, actually just Two
// 20Qs
// 10/23/2015
import java.util.Scanner;
public class TwentyQuestions {
public static void main( String[] args ) {
Scanner keyboard = new Scanner(System.in);
String ans = "N/A", type = "N/A", size = "N/A", guess = "N/A";
boolean big = true;
System.out.println( "Let's play a game. Think of an object, and I will guess it. Maybe." );
System.out.println( "1) Is it a fish, person, or a hat?" );
ans = keyboard.next();
if ( ans.equals( "fish" ) )
{
type = "fish";
}
else if ( ans.equals( "person" ) )
{
type = "person";
}
else if ( ans.equals( "hat" ) )
{
type = "hat";
}
System.out.println( "A " + type + ". Great. Is it 'big' or 'small'?" );
ans = keyboard.next();
if ( ans.equals( "big" ) )
{
big = true;
size = "big";
}
else if ( ans.equals( "small" ) )
{
big = false;
size = "small";
}
if ( type.equals( "fish" ) && ( big == true ) )
{
guess = "a great white shark";
}
else if ( type.equals( "fish" ) && ( big == false ) )
{
guess = "an anchovy";
}
else if ( type.equals( "person" ) && ( big == true ) )
{
guess = "Chief Bromden";
}
else if ( type.equals( "person" ) && ( big == false ) )
{
guess = "Peter Dinklage";
}
else if ( type.equals( "hat" ) && ( big == true ) )
{
guess = "a sombrero";
}
else if ( type.equals( "hat" ) && ( big == false ) )
{
guess = "a beanie";
}
System.out.println( "So, a " + size + " " + type + "?" );
System.out.println( "Uh... you're definately thinking of " + guess + "!" );
}
}
Picture of the output