试图使用主Java类中另一个类的方法

时间:2018-12-04 20:41:52

标签: java

我们必须创建一个自己选择的冒险游戏,而我选择做一个生物群系生存游戏。马上,我在调用存储方法的类时遇到了一些困难。我提示输入biomeAns,但它读取了它,似乎立即退出了,而没有读取和打印另一个类中方法的内容。 我想念什么?

`package com.company;
import java.util.*;
public class Main {

public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    System.out.println("What up, Bitch?");
    //String congrats = "Congratulations";

    Biomes biomeObj = new Biomes();

//Turned in a zip file w/README file containing a description of the 
project, instructions for compilation, and (sample input w/expected output)
//includes appropriate Javadoc comments
//includes at least 2 classes
//contains at least one constructor
//Program contains 2 methods
//Program includes a try...catch block
//includes a loop
//Program includes conditional statement

//intro
System.out.println("Welcome to the Biome \nYou will be prompted to choose 
between two biomes");
System.out.println("This will determine which biome you will attempt to 
survive for the next 7 days");
System.out.println(" ");

//choose biome
System.out.println("?Tundra or Desert?");
String biomeAns = scan.nextLine();
if(biomeAns == "tundra" || biomeAns == "Tundra"){
biomeObj.tundra();
}if(biomeAns == "desert" || biomeAns == "Desert"){
biomeObj.desert();
}
}
}//END MAIN`

以及我要尝试调用的类和方法,但也失败了,因为它根本没有读入这些方法:

package com.company;

public class Biomes {

public void tundra(){//send user to tundra
    System.out.println("Welcome to the Tundra");

}

public void desert(){//send user to desert
    System.out.println("Welcome to the Desert");

}

}

0 个答案:

没有答案