好的,所以我正在关注BrandonioProdtuctions YouTube 频道上的 Java 教程和。我在第 7 部分:面向对象编程简介。我遇到的问题是,当我尝试运行程序时,它在我直接粘贴在下面的类(标题为 objectIntroTest)中出现错误。
public class objectIntroTest {
public static void main(String[] args){
String x = "Hello";
objectIntro waterBottle = new objectIntro(0);
waterBottle.addwater(100);
waterBottle.drinkWater(20);
System.out.println("Your remaining water level is:"* + waterBottle.getWater());
}
}
这是另一个名为“objectIntro”的类:
public class objectIntro {
public objectIntro(){
//Default constructor
}
public objectIntro(int waterAmount){
twater = waterAmount;
}
int twater = 0; //This is how much water is in the water bottle
public void addWater(int amount){
twater = twater + amount;
}
public void drinWater(int amount){
twater = twater - amount;
}
public int getWater(){
return twater;
}
}
这是我尝试运行程序时它给我的错误消息:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method addwater(int) is undefined for the type objectIntro
The method drinkWater(int) is undefined for the type objectIntro
The operator * is undefined for the argument type(s) String, int
at objectIntroTest.main(objectIntroTest.java:6)
为什么会这样?