Assignemnt #44 and Twenty Questions
Code
///Name: Mark
///Period: 6
///Program Name: 2 Questions
///File Name: twoquestions.java
///Date finished: 10/5/15
import java.util.Scanner;
public class twoquestions
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String type, size, answer;
answer= "";
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, vegtable, or mineral? ");
System.out.println( ">" );
type = keyboard.next();
System.out.println( "" );
System.out.println( "Question 2) Is it bigger than a breadbox? " );
System.out.println( ">" );
size = keyboard.next();
System.out.println( "" );
if (type.equals("animal"))
{
if (size.equals("no"))
{
answer = "squirrel";
}
else if (size.equals("yes"))
{
answer = "moose";
}
}
else if (type.equals("vegtable"))
{
if (size.equals("no"))
{
answer = "carrot";
}
else if (size.equals("yes"))
{
answer = "watermelon";
}
}
else if (type.equals("mineral"))
{
if (size.equals("no"))
{
answer ="paper clip";
}
if (size.equals("yes"))
{
answer ="Camero";
}
}
else
{
System.out.println( "You didn't choose one of the answers loser" );
answer = "error";
}
System.out.println( "My guess is that you are thinking of a " + answer + "." );
System.out.println( "I would ask you if I'm right, but I don't actually care. " );
}
}
Picture of the output