すぐに体調を崩します。私はできる限りのことをしました!問題: コマンド ラインでプログラムを実行しようとすると、次のエラーが発生します。
エラー: シンボル 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;
}
}