【发布时间】:2018-11-23 03:22:15
【问题描述】:
我使用 Visual Studio Code,我只是创建了一个文件夹,里面有“项目”,我不喜欢在小程序中使用 netbeans、eclipse 等。
所以我正在创建一个小程序,我怀疑它会起作用,但它确实适用于 mos 部分,它创建了一个类似 rpg 的角色和第二个角色,并创建了一个模拟战斗,其中一个角色根据一个统计数据获胜.一切似乎都正常,但是当我调用 Battle(oumar, aisha); 方法时,它需要两个字符并让他们战斗,它得到一个错误说
Main.java:6: error: cannot find symbol
Battle(oumar, aisha);
^
symbol: method Battle(Character,Character)
location: class Main
因此,由于我经验不足,因此我不确定问题到底是什么。 这是主类的代码:
public class Main {
public static void main(String args[]) {
Character oumar = new Character("Oumar", 10);
Character aisha = new Character("Aisha", 9);
Battle(oumar, aisha);
}
}
这是一个单独文件中的第二个类(仍在同一个文件夹中)
public class Character {
String name;
int BattlePower;
int wins;
Character one;
Character two;
public Character(String name, int BattlePower) {
this.name = name;
this.wins = wins;
System.out.println("New character: "+ name);
this.BattlePower = BattlePower;
this.wins = wins;
System.out.println(name + "has a Battle Power of " + BattlePower);
}
public void Battle(Character one, Character two) {
this.one = one;
this.two = two;
if (one.BattlePower > two.BattlePower ) {
System.out.print("Character " + one + " has won the Battle!");
one.wins++;
System.out.print("Character one now has " + wins + " wins!");
}
else if (two.BattlePower > one.BattlePower) {
System.out.print("Character " + two + " has won the Battle!");
two.wins++;
System.out.print("Character two now has " + wins + " wins!");
}
else {
System.out.print("The two characters have tied!");
}
}
}
任何帮助都会很棒,以及将来可能对我有帮助的任何提示。
【问题讨论】:
标签: java visual-studio oop object