import java.io.*;
class Main
{
public static void main(String args[]) throws IOException
{
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
String strInput;
String strInput1;
System.out.println("Do you like cookies?:");
strInput = dataIn.readLine(); //reads data from console
try
{
if ("y".equals(strInput))
{
System.out.println("Do you like chocolate?:");
strInput = dataIn.readLine(); //reads data from console
if ("y".equals(strInput))
{
System.out.println("You must like Oreo cookies then");
}
else if ("n".equals(strInput))
{
System.out.println("If you don't like Chocolate, you must like peanut butter");
}
else
{
throw new TheException(); //calls
}
}
System.out.println("Do you like Milk?:");
strInput1 = dataIn.readLine(); //reads data from console
if ("y".equals(strInput1))
{
System.out.println("Do you like Chocolate Milk?");
strInput1 = dataIn.readLine(); //reads data from console
if ("y".equals(strInput1))
{
System.out.println("Me and you both Pal, put er' their!!");
}
else if ("n".equals(strInput1))
{
System.out.println("I don't Understand you, goodbye!!");
}
else
{
throw new TheException(); //calls
}
}
else if ("n".equals(strInput1))
{
System.out.println("Ok, so you don't like milk, your too picky!!!");
}
else
{
throw new TheException(); //calls
}
}
catch (TheException e)
{
System.out.println("Illegal input caught, please enter a Y or N");
}
System.out.println();
System.out.println("Program Ending!");
}
}
class TheException extends Exception
{
public String toString()
{
return "Illegal";
}
}
I think that should work fine for you, i havn't fully tested but.
You had an if statement that was checking if the input was = to "n", and if it was then it was printing "Do you like milk?", otherwise it was skipping this line.
if ("n".equals(strInput))
System.out.println("Do you like Milk?:");
strInput1 = dataIn.readLine(); //reads data from console
Also once you had asked whether or not they like milk, you then printed do you like chocolate milk and forgot to ask the user again, and so the last input is used as a check.
Cheers,
Chris