Programming Assignment #35
Code
/// Name: Dylan Sleeper
/// Period: 6
/// Program Name: Else and If
/// File Name: questions.java
/// Date Finished: 10/22/2015
import java.util.Scanner;
public class questions{
public static void main(String[] args){
String guess = "";
Scanner keyboard = new Scanner(System.in);
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?");
String answer1 = keyboard.next();
System.out.println();
System.out.println("Question 2) Is it bigger than a breadbox?");
String answer2 = keyboard.next();
System.out.println();
if(answer1.equals("animal")){
if(answer2.equals("no")){
guess = "moose";
}
else{
guess = "mouse";
}
}
else if(answer1.equals("vegetable")){
if(answer2.equals("no")){
guess = "carrot";
}
else{
guess = "watermelon";
}
}
else{
if(answer2.equals("no")){
guess = "paper clip";
}
else{
guess = "Camaro";
}
}
System.out.println("I bet you're thinking of a " + guess + "!");
System.out.println("I'd ask if I was right, but I'm too lazy to type in the extra code.");
}
}
Outputs