困在虚拟动物园

时间:2017-02-11 20:37:44

标签: object netbeans

我正在做一个计算机科学的虚拟动物园而且我被困住了。我们正在使用指南来浏览动物园,但我无法弄清楚如何在没有错误的情况下前进。当我跑它时,它说" 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) {

}

}

2 个答案:

答案 0 :(得分:0)

似乎有什么问题? 您能否提供有关问题的更多信息。 它似乎正在发挥作用。

您是否正在创建Guide对象?

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

之后,一切似乎都在起作用。 只要确保每个案例都有休息时间,只是为了确保一致性。 希望我帮助过。

答案 1 :(得分: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());

}

}