很快就病倒了。我已经做了我能做的一切!问题:当我尝试在命令行中运行我的程序时,我收到了这个错误:
错误:找不到符号 SimpleDotCom dot = new SimpleDotCom(); ^ ^ 符号:SimpleDotCom 类 位置:SimpleDotComTestDrive 类
这是代码:
public class SimpleDotComTestDrive {
public static void main (String[] args) {
SimpleDotCom dot = new SimpleDotCom();
int[] locations = {2, 3 ,4};
dot.setLocationCells(locations);
String userGuess = "2";
String result = dot.checkYourself(userGuess);
}
public class SimpleDotCom {
int[] locationCells;
int numOfHits = 0;
public void setLocationCells(int[] locs) {
locationCells = locs;
}
public String checkYourself(String stringGuess) {
int guess = Integer.parseInt(stringGuess);
String result = "miss";
for (int cell : locationCells) {
if (guess == cell) {
result = "hit";
numOfHits++;
break;
}
}
if (numOfHits == locationCells.length) {
result = "kill";
}
System.out.println(result);
return result;
}
}