Assignment #44: Twenty Questions...Or Just Two
Code
/// Name: Kiran O'Farrell
/// Program name: Two Questions
/// File name: TwoQuestions.java
/// Date completed: 11/18/15
import java.util.Scanner;
public class TwoQuestions {
public static void main (String[] args) {
Scanner keyboard = new Scanner(System.in);
int avm, breadbox;
System.out.println("Is the object an animal, vegetable or mineral?");
System.out.println("1. Animal");
System.out.println("2. Vegetable");
System.out.println("3. Mineral");
avm = keyboard.nextInt();
if (avm > 3) {
System.out.println("Please enter a valid response.");
}
System.out.println("Is it bigger than a breadbox?");
System.out.println("1. Yes");
System.out.println("2. No");
breadbox = keyboard.nextInt();
if (breadbox > 2) {
System.out.println("Please enter a valid response.");
}
if (breadbox == 1) {
if (avm == 1) {
System.out.println("The object is a moose.");
}
else if (avm == 2) {
System.out.println("The object is a watermelon.");
}
else if (avm == 3) {
System.out.println("The object is a Camaro.");
}
else if (breadbox == 2) {
if (avm == 1) {
System.out.println("The object is a squirrel.");
}
}
else if (avm == 2) {
System.out.println("The object is a carrot.");
}
else if (avm == 3) {
System.out.println("The object is a paperclip.");
}
}
}
}
Picture of the output