Object 困在虚拟动物园里
我在做一个计算机科学的虚拟动物园,我被卡住了。我们用向导在动物园里导航,但我不知道怎么走才能不出错。当我运行它时,它会显示“Null!Null,我不知道该怎么做。我对编码非常陌生,所以感谢您的帮助Object 困在虚拟动物园里,object,netbeans,Object,Netbeans,我在做一个计算机科学的虚拟动物园,我被卡住了。我们用向导在动物园里导航,但我不知道怎么走才能不出错。当我运行它时,它会显示“Null!Null,我不知道该怎么做。我对编码非常陌生,所以感谢您的帮助 class Guide { private String name; int Selection; int Selection1; int Selection3; int Selection2; int choice; Scanner inputScanner = new Scanner (Syste
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) {
}
}什么问题? 你能提供更多关于问题所在的信息吗。 它似乎起作用了 是否正在创建引导对象
public class test {
public static void main(String[] args) {
Guide guide = new Guide();
guide.welcomeusertozoo();
}
}
从那以后,一切似乎都在运转。
只要确保你在每一个案例上都有突破,以确保一致性。
希望我能帮上忙。这是主要的:
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());
}
}
有3个超类,每个超类将有4个子类。你必须能够选择你想看到的超类,然后回来做另一个选择。这是一个问题…第二个问题是我刚才说的空值问题。我不能复制你的空值问题,因为这里的一切都很好,来生成另一个c选择您应该添加一个新函数,在其中询问用户现在想要看到什么,并在切换后调用该函数。这意味着当用户做出第一个选择时,在看到子类后,它将询问用户现在想要做什么。而不是调用creatureSelection()你可以调用这个新函数。对不起,我不太擅长这个,但是你怎么调用这个函数呢?我想这就是你想要构建的,我刚刚组织好了你的代码,所以我尝试了一下,但在我的主要项目中,它说“欢迎用户在课堂指南中访问动物园的方法不能应用于给定的类型”