有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何修复这些错误以及其他建议?

已经两天多了,我一直在查看我的代码,但我仍然不知道代码可能存在什么问题: 它不断地在Q11、Q7、Q5的if和else部分给我一个错误

错误:'else不带'if'(//Q11-else、//Q7-else和//Q5-else)

如果您对我的代码还有任何建议,请随时告诉我:)

import java.awt.*;
import hsa_ufa.Console; 

public class Panophobia {
  static Console c = new Console(1350,1000); 
  
  public static void main(String[] args) throws InterruptedException
  {
  
  // VARIABLES
  
  String answer, userInputStr;
  int userInput, chestNumber;
  
  //INPUT
  
  // INPUT: Start
  Image item1Image = Toolkit.getDefaultToolkit ().getImage (c.getClass().getClassLoader().getResource("ward.jpg"));
  c.drawImage(item1Image, 0, 0);
  
  // FONT + COLOUR
  c.setColor(new Color(255,255,255));
  c.setFont(new Font("Chomsky",Font.PLAIN,50));
  
  c.drawString("Panophobia",500,300);
  
  c.setFont(new Font("Open Sans Semibold",Font.PLAIN,20)); // FONT
  
  c.drawString("Press any Key to Start",520,350);
  
  c.getChar();
  c.clear();

  // INPUT: Game Start
  chestNumber = (int)(Math.random() * 8) + 1;
  
  // PROCESSING + OUTPUT (RUNNING GAME)
  
  c.setColor(new Color(0,0,0));

  //Q1 if
  Image item2Image = Toolkit.getDefaultToolkit ().getImage (c.getClass().getClassLoader().getResource("hotel.jpg"));
  c.drawImage(item2Image, 0, 0);
  c.getChar();
  c.clear();
  
  //Q1 if
     { c.println("You've arrived at your destination, the one and only 'Palace Hotel'. You'll need to check in, let's figure out what way to go first: Left or Right?");
      answer = c.readLine();
      
  if (answer.equalsIgnoreCase("Left"))  //Q2 if 
  {  c.println("You meet a dead end, but there are two doors on opposite sides, do you wish to open one? (y/n)");
     answer = c.readLine();
  
   if (answer.equalsIgnoreCase("y")) //Q3 if
   {  c.println("Which door do you choose to open? (Left, Right)");
      answer = c.readLine();
  
    if (answer.equalsIgnoreCase("Left")) //Q4 if
    {  c.println("You open the ominous door and to your surprise, the room is empty. You walk around the room and find a couple of items in the drawers and compartments, a pocket knife, a medical kit, a flask, and a key chain with 5 different keys. There are a total of 8 locked drawers on a dresser are locked (only one key will unlock the drawer), which ones do you choose to unlock? 1, 2, 3, 4, 5, 6, 7, and/or 8?");
       userInput = c.readInt();
  
     if (Math.random() < chestNumber) //Q5 if
     { c.println("A Funnel Web Spider bites you, you have less than an hour to survive.");
       c.println("You grab the medical kit and you tightly wrap a bandaid around the bite.");
             
       { c.println("You turn around and walk back where you started, but something seems off, why are there no people around?"); //Q6 if
        c.println("You should ask around! (Ask: concierge or housekeeper)");
        answer = c.readLine();
                  
       if (answer.equalsIgnoreCase("housekeeper")) //Q7 if
       { c.println("what can I help you with?");
         c.println("what do you mean there’s no one around?");
         c.println("look over there, the concierge is really busy attending to the guests!");
         c.println("you anxiously tap your finger against the black suitcase, you cannot look at her in the eyes.");
         c.getChar();
         c.clear();
                    
         { c.println("You've arrived at the Radio Station, it seems to be abandoned. Do you want to enter the building? (y/n)"); //Q8 if
          answer = c.readLine();

         if (answer.equalsIgnoreCase("y"))  //Q9 if
         { c.println("You enter the station, there are two rooms you can enter which one do you want to open first? (1/2)");
           answer = c.readLine();
  
          if (answer.equalsIgnoreCase("1")) //Q10 if
          { c.println("There’s blood splattered on one wall, are you brave enough to inspect? (y/n)");
            answer = c.readLine();
 
           if (answer.equalsIgnoreCase("y")) //Q11 if
           { c.println("There are no bodies, just blood. There’s a stench in the room that renders you unconscious.");
             c.getChar();
             c.clear();
             
            { c.println("Now that you’ve checked in, it’d be best to buy some things at a store. What store would you like to head over to? (Convenience Store/SuperMarket)");
            answer = c.readLine();
            
             if (answer.equalsIgnoreCase("SuperMarket")) //Q12 if 
             { c.println("The store looks full of people, you enter the store and take some pills to help with the anxiety, food, water and a flashlight/batteries.");
              c.println("Maybe you should head home.");
              c.println("You begin walking down the road you had driven on to get to the hotel, after walking for half an hour, all you seem to come across is a forest. You hear a loud thud somewhere near these green bushes, do you want to check it out? (y/n)");
              answer = c.readLine();
  
              if (answer.equalsIgnoreCase("y")) //Q13 if
              { c.println("You slowly walk over to the bush, there’s some light rustling, tension starts to build up in your body, your hand shakes as you reach to separate the small branches and leaves to see what's inside. The rustling becomes louder each time you put your hand closer to the bush, there’s a loud squeal, suddenly, a small lop bunny hops out, making you fall onto the soft green grass. You find a car key, do you want to take it? (y/n)");
               answer = c.readLine();
  
              if (answer.equalsIgnoreCase("y")) //Q14
              { c.println("You quickly grab the keys, 'I should find that car.' You look nearby for whatever car those keys belong to, after an hour of searching, you finally come across it. You decide to visit the Radio Station.");
                c.println("Congratulations! You now have a car.");
                c.getChar();
                c.clear();
              }
               else //Q14 else
               { 
               c.println("You decide to walk to the Radio Station.");
               }
              }
              
              else if (answer.equalsIgnoreCase("n")) //Q13 else
              { 
              c.println("I can't take someone else’s keys, it's wrong to do so");
              }
             }
            
             else if (answer.equalsIgnoreCase("Convenience Store")) //Q12 else
             { 
             c.println("It seems like the convenience store is closed!");
             }
            }
 
            else  //Q11 else
            { 
            c.println("You walk away from the blood and leave the building.");
            }
           }
           
           else //Q10 else
           { 
           c.println("There was no blood, it was a hallucination.");
           }
          }
                                  
          else //Q9 else
          { 
          c.println("There is a file compartment filled with voice and videotapes, you watch and listen to every single one. You’ve gained some knowledge of what had happened to this town.",10,300);
          }
         }
                              
         else //Q8 else
         { 
         c.println("You walk back to the road. Out of the corner of your eye, you see a large fast car coming your way. The car runs you over.");
         }
        }
                          
        else if (answer.equalsIgnoreCase("concierge"))//Q7 else
        { 
        c.println("You walk towards the concierge's desk and begin your check in.");
        }
       }
                        
       else //Q6 else
       { 
       c.println("It seems like the person you're looking for isn't here.");
       }
      }
                     
      else //Q5 else
      { 
      c.println("There's nothing in that drawer.");
      }
     }
                    
     else if (chestNumber < Math.random()) //Q4 else
     { 
     c.println("Wrong Key!");
     }
    } 
                  
    else if (answer.equalsIgnoreCase("Right")) //Q3 else
    { 
    c.println("There's nothing in that room, boring.");
    c.println("You turn around and walk back where you started, but something seems off, why are there no people around? You should ask around! (Ask: waitress, concierge, security guard, or housekeeper)");
    }
   }
                 
   else if (answer.equalsIgnoreCase("n")) //Q2 else
   { 
   c.println("You walk up to the front desk and begin your check-in, they require some kind of ID, you give them your passport.");
   }
  }
            
  else if (answer.equalsIgnoreCase("Right")) //Q1 else
  { 
  c.println("You walk up to the front desk and begin your check-in, they require some kind of ID, you give them your passport.");
  }
 }
 
  }
}

共 (0) 个答案