Originally Posted by
Ooogel
.
.
.
do{
int inputNumber = keyboard.nextInt();
if(inputNumber == 0){
if(start = true){
out.println("YOU HAVE JUST LEFT DUNDEE MIDDLE SCHOOL.");
out.println("YOU ARE RIDING HOME ON THE BUS WHEN ALL");
out.println("OF A SUDDEN YOU SEE A MAJOR TRAFFIC JAM");
out.println("AW MAN! YOU THINK. BUT THEN YOU SEE THE");
out.println("CRATER IN THE GROUND. THE BUS DRIVER OPENS");
out.println("THE DOORS AND EVERYONE RUNS OUT. YOU RUN");
out.println("UNTIL YOU REACH YOUR HOME. ITS DESERTED.");
out.println("YOU REALIZE YOU HAVE TO FIGURE OUT WHAT");
out.println("IS GOING ON");
out.println("");
out.println("PRESS 9 TO GET YOUR OPTIONS");
}else
if(inputNumber == 9){
if(home == true){
out.println("PRESS 1 TO GO NORTH INTO HOUSE");
out.println("PRESS 2 TO GO EAST TO INTERSECTION");
out.println("PRESS 3 TO GO SOUTH TO PARK");
out.println("PRESS 4 TO GO WEST TO SHOP");
home = true;
By adding code tags to your original code so that I can check out your formatting, I think I may see a problem. Could be "the" problem, I'm thinking...
Anyhow, in spite of your indentation, the 'else' goes with the "if(start)", not with the "if(inputNumber == 0)"
Java compilers ignore indentation. And it's only convenient for Humans if the style results in something that is visually consistent with the logical organization.
Anyhow...
Here: Ill take your code with no changes other than a more spread-out style of indentation that is consistent with the way that the compiler sees it. (Well, I added some closing braces that will occur later on in your code, too.)
do{
int inputNumber = keyboard.nextInt();
if(inputNumber == 0)
{
if(start = true)
{
out.println("YOU HAVE JUST LEFT DUNDEE MIDDLE SCHOOL.");
out.println("YOU ARE RIDING HOME ON THE BUS WHEN ALL");
out.println("OF A SUDDEN YOU SEE A MAJOR TRAFFIC JAM");
out.println("AW MAN! YOU THINK. BUT THEN YOU SEE THE");
out.println("CRATER IN THE GROUND. THE BUS DRIVER OPENS");
out.println("THE DOORS AND EVERYONE RUNS OUT. YOU RUN");
out.println("UNTIL YOU REACH YOUR HOME. ITS DESERTED.");
out.println("YOU REALIZE YOU HAVE TO FIGURE OUT WHAT");
out.println("IS GOING ON");
out.println("");
out.println("PRESS 9 TO GET YOUR OPTIONS");
} // Goes with if(start...)
else if(inputNumber == 9)
{
if(home == true){
out.println("PRESS 1 TO GO NORTH INTO HOUSE");
out.println("PRESS 2 TO GO EAST TO INTERSECTION");
out.println("PRESS 3 TO GO SOUTH TO PARK");
out.println("PRESS 4 TO GO WEST TO SHOP");
home = true;
.
.
.
}// Added by Zaphod_b: Goes with if (home == true)
.
.
.
} // Added by Zaphod_b: Goes with else if(inputNumber == 9)
} // Added by Zaphod_b: Goes with if(inputNumber == 0)
} while (Loop continuation boolean expression goes here); // Added by Zaphod_b: End of the do { stuff
Putting human-oriented comments on closing braces makes it easier for others to proofread and see if the code is consistent with your expressed intent. (Makes it easier for
you to remember what you had in mind if you ever revisit the code for purposes of debugging or feature-enhancement or whatever.)
Bottom line (just a suggestion, really): If your text editor has features that let you see matching braces, turn on that feature. If it doesn't have that feature, find one that does. If your editor has an "autoindent" feature, turn it on and don't fight it. If it doesn't have that feature find one that does. You will thank me later.
Of course if that organization is not what you had in mind and I'm pretty sure it isn't, then maybe throw a closing '}' before the "else..." and unindent stuff below that or some such thing.
Hmmm...
What's the name of the reverse operation of "indent" ?
Is it really "unindent" ?
Why not "undent" ? (Shorter, more elegant.)
Or, better yet "outdent" ? (Logically consistent: "out" is opposite of "in," right?)
English is a lot more complicated and less precise than Java, right?
I mean, sometimes I feel as if I am in a maze of twisty little passages, all alike...
Cheers!
Z