Saturday, October 18, 2014

Compiles correctly, but won't display


So, I'm writing this program, and when I compile it it says Process Completed, but when I run it, it only goes through the first two if statements and won't do the case. I checked it and my brackets line up, and there obviously isn't any syntax error. The first two answers are 41 and right.


import static java.lang.System.*;

import javax.swing.JOptionPane;

import java.util.*;

public class area51

{

public static void main(String args[])

{

Scanner doctorwho = new Scanner(System.in);

//************************* definition ***************************

int openCage = 41;

int tryCage = 0;

String StryCage = "";

String filler = "";

String leftRight = "";

String left = "left";

String right = "right";

String door = "door";

String sleepingGuard = "";

double shipTrial1 = 1003.84;

double TryshipTrial1 = 0;

String shipTrial2 = "";

String incorrectly = "incorrectly";

String shipTrial3 = "";

String startScreen = "AREA 51: TRAPPED!!!!!!!!!!!!!!! " +

"You were taking a quick flight around the galaxy one day " +

"when you crashed on Earth. Sadly, the government commandeered you and your " +

"ship, no doubt for nefarious purposes. But, the guard outside your prison " +

"has fallen asleep, giving you a chance to examine the lock. You do so, and " +

"find that, for some reason that has been forever lost to the sands of time, " +

"you must solve a simple mathematics equation in order to unlock the door: " +

"9*4+8-3.";

String wrongAnswer = "You type whatever it is you typed into the ship's console." +

"It whirrs, buzzes, sparks fly from the screen. You stand up and reach " +

"for the door, and the last thing you hear is a long, low beep. " +

"The ship self destructs, and when the smoke clears it's as if it was " +

"never here.";

String lullaby = "lullaby";

String deathMetal = "death metal";

String shootingatYou = "You answer the question correctly, sneak past the " +

"sleeping guard, and move down the hall. This simply isn't your " +

"day, however, because now people are shooting at you! Dodge " +

"left, or right?";

System.out.println(startScreen);

tryCage = doctorwho.nextInt();

StryCage = "" + tryCage;

out.println(StryCage + " " + openCage+ "Q");

if (tryCage == openCage)

{

out.println("You answer the question correctly, sneak past the " +

"sleeping guard, and move down the hall. This simply isn't your " +

"day, however, because now people are shooting at you! Dodge " +

"left, or right? Choose wisely.");

leftRight = doctorwho.next();


if (leftRight.equalsIgnoreCase(right) == true)

{ //CURLY BRACES

out.println("You dodge all the bullets and make it out of " +

"there, which only gets you to yet another hallway, this one " +

"much more dilapidated than the rest. You come upon a mysterious " +

"and bloody door. Do you:" +

"<1> Try to open the door." +

"<3> Keep along your merry way." +

"Type the number of the choice you want.");

switch (door) {

case "1":

out.println("You try to open the door, only to discover " +

"that it's locked. What a surprise here in this top secret " +

"government area. In any case, you quickly discover that " +

"to get the key, you'll need to steal it off of that " +

"sleeping security guard from a bit ago. To ensure that he " +

"stays safely in dreamland you can either play a lullaby " +

"or metal off of your handy dandy iPod. Choose wisely." +

"Type the name of the genre.");

sleepingGuard = doctorwho.nextLine();

if (sleepingGuard.equalsIgnoreCase(lullaby))

{

out.println("You played the lullaby. Sadly, this woke him " +

"up, and he immediately strangled you, Simpsons style.");

}

else

if (sleepingGuard.equalsIgnoreCase(deathMetal))

{ //CURLY BRACES

out.println("You, for some reason, chose to play death " +

"metal to keep the guard asleep, which somehow worked! " +

"The guard slumbers peacefully as you steal the key from " +

"him. You run back to the mysterious door and open it " +

"only to find another member of your species, bloodied " +

"and unconcious. Will you:" +

"<1> Take him with you. Bros before imminent death." +

"or, <2> Leave him. He won't know.");

switch ("takeLeave")

{

case "1":

out.println("You took him with you. While noble, that was ill-advised, " +

"because dragging along a comatose comrade slowed you down enough for " +

"the humans to find you and put both of you back in captivity.");

break;

case "2":

out.println("You didn't take along your fallen future friend. While some " +

"may call that heartless, we call it evolutionarily wise, because you " +

"survived and found your ship! Do you: " +

"<1> Repair it, OR " +

"<2> Continue on foot? ");

}

switch ("repairWalk")

{

case "1":

out.println("You chose to repair your ship. Smart move. Now you must solve a " +

"short series of questions in order to activate the repair functions." +

"Question One: " +

"7*6/3.27+1000-9. Answer up to two decimal places. Don't add commas.");

TryshipTrial1 = doctorwho.nextDouble();

String Stryshiptrial1 = Double.toString(TryshipTrial1);

if (Stryshiptrial1.equals(shipTrial1) == true)

{

out.println("Correct! On to the next puzzle! If D = D and E = E, " +

"which comes first? Use uppercase.");

shipTrial2 = doctorwho.next();

if (shipTrial2.compareTo("D") == 0)

{

out.println("Correct! Last Puzzle! What English " +

"word is always spelled incorrectly?");

shipTrial3 = doctorwho.nextLine();

if (shipTrial3.equalsIgnoreCase(incorrectly) == true)

{

out.println("Correct! Your ship takes off, and for a while it's smooth sailing. " +

"You're considering putting it on autopilot and taking a nap until it's time " +

"to exit the atmosphere when those ne'er-do-wells at Area 51 start shooting " +

"at you. After a harrowing battle, your ship crashes in the Nevada desert. " +

"You scramble out of the ship and see officers heading toward the ship. You turn " +

"and run. Up ahead you see a cave. Will you: "+

"<1> Go into the cave " +

"<2> Bury yourself for camouflage until they stop looking for you. ");

switch ("caveCamo")

{

case "1":

out.println("You enter the cave. It's very dark and dank, just generally " +

"cave-like. You walk further into the blackness, using your natural night " +

"vision to see and just generally minding your own business, when someone" +

"hits you in the face with a rock. \"Expletives!\", you shout. \"Language!\"," +

"you hear. As you stand there rubbing your wound and wondering how this day" +

"could possibly get any stranger, a spry old hermit emerges from the gloom." +

"\"What are you doing in my cave?\" he demands. " +

"\"What are you doing in a cave?\" you shout back. \"I asked you first!\" he says." +

"The two of you glare at each other. Finally, the old man harrumphs and throws " +

"a wadded up ball of paper at you. When you unfold it, you find it's a list of " +

"numbers. When you look back up, you see the spry old hermit rapidly disappearing " +

"into the cave. Do you follow him (type follow) or not (type no)?" );

// if (follow

//You're doing well for yourself.

//else

//You starve to death in a cave.

}

}

else

if (shipTrial3.equalsIgnoreCase(incorrectly) == false)

{

out.println("Incorrect! And such a shame too, you were so close to " +

"the end. The answer was incorrectly. The word flashes on the " +

"console screen as alarms blare and robotic arms strap you to your " +

"chair. The words: <THIS WILL NOT TURN OUT WELL FOR YOU> scroll " +

"across the screen. \"You're telling me,\" you say, an instant " +

"before the ship blows up.");

}

}

else

if (shipTrial2.compareTo("E") == 0)

{

out.println("Incorrect. As you type E, the ship emits a long, low chuckle. " +

"Alarms blare. Sparks fly from the console. Bars come from your seat and lock " +

"you into place. \"This can't possibly end well.\", you think, as the ship self- " +

"destructs.");

}

}

//String STryshipTrial1 = Double.toString(TryshipTrial);

//else if (STryshipTrial1.equals(shipTrial1) == false)

//{

// out.println("wrongAnswer");

//}

break;

case "2":

out.println("You decided to keep walking, past the only ship capable of taking " +

"you home. Unsurprisingly, this did not turn out well");

}

}

case "3":

out.println("You keep moving and are eventually recaptured " +

"and taken back to your cage thing. Reload the game to try" +

"again.");

break;

//CURLY BRACE

//CURLY BRACE

//CURLY BRACE


}

} //CURLY BRACE

else if (leftRight.equalsIgnoreCase(left) == true)

{

out.println("You dodged left, directly into a bullet, which " +

"lodged iself into your head and killed you instantly. You should" +

"have dodged right, which was right, see? It's our own paltry " +

"attempt at humor.");

}


}

else

if (StryCage.equals(openCage) == false)

{

out.println("The cage didn't open, mostly because you answered " +

"incorrrectly. Your efforts woke the guard and he stabbed you in " +

"the face with a pitchfork, killing you instantly.");

}

}


}



No comments:

Post a Comment