If statement part 2 #44 (And you were expecting twenty)

Code

/// Name: Amir Salehi
/// Period: 7
/// Program Name: Two Questions
/// File Name: TwoQuestions.java
/// Date Finished: Oct 26, 2015


import java.util.Scanner;

public class TwoQuestions {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        String choice1, choice2, result;

        System.out.println("TWO QUESTIONS!\nThink of an object, and I'll try to guess it.\n");
        System.out.print("Question 1: Is it an animal, vegetable, or mineral?\n> ");

        choice1 = input.nextLine();

        System.out.print("\nQuestion 2: Is it bigger than a breadbox?\n> ");
        choice2 = input.nextLine();

        if (choice1.equalsIgnoreCase("animal")) {
            if (choice2.equalsIgnoreCase("yes")) {
                result = "giraffe";
            } else {
                result = "mouse";
            }
        } else if (choice1.equalsIgnoreCase("vegetable")) {
            if (choice2.equalsIgnoreCase("yes")) {
                result = "watermelon";
            } else {
                result = "carrot";
            }
        } else {
            if (choice2.equalsIgnoreCase("yes")) {
                result = "smart car";
            } else {
                result = "paperclip";
            }
        }

        System.out.println("\nYou were probably thinking of a " + result + ".");

    }

}
    

Picture of the output

Assignment 7

Back to Homepage