I have searched the forum for this error but can't seem to figure it out.
Why are the variable q2,q3 not being initialized, yet q1 is? Thanks all help is appreciated.
This is how the outcome should be similar to:
WELCOME TO MITCHELL'S TINY ADVENTURE!
You are in a creepy house! Would you like to go "upstairs" or into the "kitchen"?
kitchen
There is a long countertop with dirty dishes everywhere. Off to one side there is, as you'd expect, a refrigerator. You may open the "refrigerator" or look in a "cabinet".
refrigerator
Inside the refrigerator you see food and stuff. It looks pretty nasty. Would you like to eat some of the food? ("yes" or "no")
no
import java.util.Scanner;
public class App1 {
public static void main(String[] Args) {
Scanner keyboard = new Scanner(System.in);
String q1;
String q2;
String q3;
String a = "upstairs";
String b = "kitchen";
String c = "refrigerator";
String d = "cabinet";
String e = "yes";
String f = "no";
String g = "hallway";
String h = "bedroom";
String i = "bathroom";
System.out.println("Welcome To Mitchell's Tiny Adventure!");
System.out.println();
System.out.println("You are in a creepy house, would you like to go upstairs or into the kitchen?");
System.out.print(">");
q1 = keyboard.nextLine();
System.out.println();
if (q1.equals(a)) {
System.out.println("Upstairs you see a hallway. At the end of the hallway is the master");
System.out.println("\"bedroom\". There is also a \"bathroom\" off the hallway. Where would you like");
System.out.println("to go?");
System.out.print(">");
q2 = keyboard.nextLine();
System.out.println();
} else if (q1.equals(b)) {
System.out.println("There is a long countertop with dirty dishes everywhere. Off to one");
System.out.println("side there is, as you'd expect, a refrigerator. You may open the \"refrigerator\"");
System.out.println("or look in a \"cabinet\".");
System.out.print(">");
q2 = keyboard.nextLine();
System.out.println();
}
if (q2.equals(c)) {
System.out.println("Inside the refrigerator you see food and stuff. It looks pretty nasty.");
System.out.println("Would you like to eat some of the food? (\"yes\" or \"no\")");
System.out.print(">");
q3 = keyboard.nextLine();
System.out.println();
} else if (q2.equals(d)) {
System.out.println("Inside the cabinet is the boogie man, Are you scare? \"yes or no\"");
q3 = keyboard.nextLine();
System.out.println();
}if (q2.equals(g)){
System.out.println("You fall in the hallway can you make it? \"yes or no\"");
q3 = keyboard.nextLine();
System.out.println();
}else if (q2.equals(h)){
System.out.println("You run into the bedroom were there are monsters live are you afraid \"yes or no\"");
q3 = keyboard.nextLine();
System.out.println();
}else if(q2.equals(i)){
System.out.println("You run into the bathroom do you have to use it \"yes or no\"");
q3 = keyboard.nextLine();
System.out.println();
}
}
}
Aucun commentaire:
Enregistrer un commentaire