Problem 35

Two More Questions

Using if statements with compound conditions (like &&), make a guessing game of two questions similar to the Twenty Questions assignment.

However, this time you must accomplish it using if statements with compound conditions and you must not use else if or else or nested ifs.

Again, here are some sample responses, for the non-creative among you.

           inside            outside     both
alive      houseplant        bison       dog
not alive  shower curtain    billboard   cell phone
TWO MORE QUESTIONS, BABY!

Think of something and I'll try to guess it!

Question 1) Does it stay inside or outside or both? outside
Question 2) Is it a living thing? yes

Then what else could you be thinking of besides a python?!?
TWO MORE QUESTIONS, BABY!

Think of something and I'll try to guess it!

Question 1) Does it stay inside or outside or both? both
Question 2) Is it a living thing? no

Obviously the nonliving, inside/outside thing on your mind is a dead ant!

What to do on your own

You may notice that your program doesn’t properly compare strings. To realiably compare strings use the .equals() method. For example:

String someString = "Hello";
if (someString.equals("Goodbye")) {
    // do whatever  
}


◄ 34: Age Messages 3 36: BMI Categories ►



Adapted from ProgrammingByDoing.com
©2013 Graham Mitchell

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.