2017-02-11 4 views
0

Я занимаюсь виртуальным зоопарком в области информатики, и я застрял. Мы используем руководство для навигации по зоопарку, но я не могу понять, как обойтись без ошибок. Когда я запускаю его он говорит: «Null! Null, и я понятия не имею, что делать. Я не являюсь довольно новым для кодирования спасибо вам за вашу помощь.Застрял на виртуальном зоопарке

class Guide { 
private String name; 
int Selection; 
int Selection1; 
int Selection3; 
int Selection2; 
int choice; 
Scanner inputScanner = new Scanner (System.in); 

void welcomeusertozoo() { 

     System.out.println("Hello! Welcome to Cringe Jarin! A Zoo full of cringy creative creatures. Im Fred. What is your Cringy Name?"); 
name = inputScanner.next(); 
System.err.println("Ewww..... How cringy. Well, Welcome " + name + "! What creatures would you like to visit First?" 
     + "\n 1.Ogres" 
     + "\n 2.Vampires" 
     + "\n 3.Rats \n\n"); 
choice = inputScanner.nextInt(); 
    creatureselection(choice); 
} 

void creatureselection(int Selection) { 

    switch (Selection) { 

     case 1: System.out.println("Plug up the nose and close those eyes! These creatures are Ugly! who Would you Like to visit...\n Please press 1 to go meet the commander himself, Ogre E Lee. \n Please press 2 to go meet the one and only Ogrewall Jackson. \n Please press 3 to meet the wonderful Mr.GreenBean. \n Please press 4 to meet the rebellious William Shrallace. \n\n"); 
      choice = inputScanner.nextInt(); 

     switch (choice){ 
      case 1: System.out.println("Commander Ogre. E Lee Here! \n\n"); 
      case 2: System.out.println("This is the impeccable, the amazing, one and only Ogrewall Jackson \n\n"); 
      break; 
      case 3: System.out.println("This is the fashionable, the sexy, the fabulous GreenBean \n\n"); 
      break; 
      case 4: System.out.println("This is the free, the bravest heart I know, the impecable William Shrallace \n\n"); 
      default: System.out.println("We do not have a creature under that selection at the moment. Please choose 1 or 2 or 3 \n\n"); 

     } 

     break; 


     case 2:System.out.println("Dont have a scarf? Oh.... watch your necks! Who would you like to visit...\n Please press 1 to go meet the spooky Dio. \n Please press 2 to go meet the truly bone chilling Diego. \n Please press 3 to meet the bloodthirsty Big White Bat. \n Please press 4 to meet the Bold Mubat. \n\n"); 
     choice = inputScanner.nextInt(); 
     switch (choice){ 
      case 1: System.out.println("Dio \n\n"); creatureselection(2); 
       break; 
      case 2: System.out.println("Diego \n\n"); creatureselection(2); 
       break; 
      case 3: System.out.println("Big White bat \n\n"); creatureselection(2); 
       break; 
      case 4: System.out.println("Bold Mubat \n\n"); creatureselection(2); 
       break; 
       default: System.out.println("We do not have a creature under that selection at the moment. Please choose 1 or 2 or 3 \n\n"); 
      creatureselection(2); 
     } 


     break; 


     case 3:System.out.println("Pull out the Cheese but dont let it rip! These creatures are Cringy! Who would you like to visit...\n Please press 1 to go meet the Odd Ratty Weisau. \n Please press 2 to go meet the backstabbing Risa. \n Please press 3 to meet the permanently sad Dindin. \n Please press 4 to meet the sketchy Markymouse. \n\n"); 
     choice = inputScanner.nextInt(); 
     switch (choice) { 
      case 1: System.out.println("Ratty Weisau \n\n"); creatureselection(3); 
       break; 
      case 2: System.out.println("Risa \n\n"); creatureselection(3); 
       break; 
      case 3: System.out.println("Dindin \n\n"); creatureselection(3); 
       break; 
      case 4: System.out.println("Markymouse \n\n"); creatureselection(3); 
       break; 
       default: System.out.println("We do not have a creature under that selection at the moment. Please choose 1 or 2 or 3 \n\n"); 
      creatureselection(3); 
     } 
      break; 
     default: System.out.println("We do not have a creature under that selection at the moment. Please choose 1 or 2 or 3 \n\n"); 
      creatureselection(1); 


    } 



} 
void setName(String fred) { 

} 

}

ответ

0

Что, кажется, проблема? Можете ли вы предоставить более подробную информацию о том, что это проблема. это, кажется, работает.

вы создаете объект Guide?

public class test { 
    public static void main(String[] args) { 
     Guide guide = new Guide(); 
     guide.welcomeusertozoo(); 
    } 
} 

После этого все, кажется, работает. Просто убедитесь, что у вас есть перерывы в каждом случае, чтобы обеспечить согласованность. Надеюсь, я помог.

+0

Есть 3 суперкласса и для каждого из них есть будет 4 подклассов. Вы должны быть в состоянии выбрать, какой из них вы хотели бы видеть, а затем вернуться, чтобы сделать другой выбор. Это одна проблема ... Вторая проблема - это то, что я говорю. – Alec

+0

Я не могу реплицировать вашу проблему с Null, так как здесь все работает, чтобы сделать другой выбор, вы должны добавить новую функцию, где вы спросите, что пользователь хочет увидеть сейчас, и вызовите эту функцию после переключения. Это будет означать, что когда пользователь сделает первый выбор, и, увидев подкласс, он попросит пользователя, что он хочет сделать сейчас. Вместо вызова creatureSelection() вы вызываете эту новую функцию. –

+0

Извините, я не очень хорош в этом, но как вы называете эту функцию? – Alec

0

Это главное:

public class ZooProject { 

public static void main(String[] args) { 

    Rat RattyWiseau = new Rat(); 
    Ogre OgreELee = new Ogre(); 
    Vampire Dio = new Vampire();  
    Guide Fredtheguide = new Guide(); 




    //ask user for name 
    RattyWiseau.setName("Ratty Wiseau"); 
    Dio.setName("Dio"); 
    // Fredtheguide.setName("Fred"); 
    OgreELee.setName("Ogre E Lee"); 
    Fredtheguide.welcomeusertozoo(); 
    System.out.println(OgreELee.getName()); 

} 

} 
Смежные вопросы