Assignment #44 and Twenty Questions

Code


  /// Name: Tim Chuang
/// Period: 7
/// Program Name: Twenty Questions
/// File Name: TwentyQuestions.java
/// Date Finished: 12/1/2015
import java.util.Scanner;

class TwentyQuestions
{
      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 animal, and I'll try to guess it." );
          System.out.println();
          System.out.println( "Question 1) Is it an animal, a machine, or natural?" );
          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("machine") )
          {
              a = "phone";
              b = "car";
          }
          else if ( answer1.equals("natural") )
          {
              a = "grass";
              b = "tree";
          }
          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

Assignment 44