Assignment 44: 20 Questions, No Just 2
Code
/// Name: Ryan McAteer
/// Period: 5
/// Program Name: 20 Questions, No Just 2
/// File Name: Assignment44java
/// Date Finished: 10/23/15
import java.util.Scanner;
class Assignment44
{
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(n) " + c + "." );
System.out.println( "I would ask if I'm right, but I don't actually care." );
}
}
Picture of the output