Assignment 44
code
///Name: Mutsu Osoegawa
///Period: 7
///Project Name: Twenty Questions... well, actually just Two
///File Name: TwoQuestions.java
///Date: 10/13/2015
import java.util.Scanner;
public class TwoQuestions
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String answer1, answer2, yes, no, a, b, c;
System.out.println( "TWO QUESTIONS!" );
System.out.println( "Think of an object, and I'll try to guess it. " );
System.out.println();
System.out.println( "Question 1) Is it an animal, vegetable, or mineral? " );
System.out.print( "> " );
answer1 = keyboard.next();
System.out.println();
System.out.println( "Question 2) Is it bigger than a breadbox? " );
System.out.print( "> " );
answer2 = keyboard.next();
System.out.println();
if ( answer1.equals("animal") )
{
a = "squirrel";
b = "moose";
}
else if ( answer1.equals("vegetable") )
{
a = "carrot";
b = "watermelon";
}
else if ( answer1.equals("mineral") )
{
a = "paper clip";
b = "Camaro";
}
else
{
a = "error";
b = "error";
}
if ( answer2.equals("yes") )
{
c = b;
}
else if ( answer2.equals("no") )
{
c = a;
}
else
{
c = "error";
}
System.out.println( "My guess is that you are thinking of a " + c + "." );
System.out.println( "I would ask you if I'm right, but I don't actually care. " );
}
}