import java.util.ArrayList;
public class SimpleDotCom {
private ArrayList locationCells;
public void setLocationCells(ArrayList loc) {
locationCells = loc;
}
public String checkYourself(String userinput) {
int index = locationCells.indexOf(userinput);
String result = "miss";
if(index >= 0){
locationCells.remove(index);
if(locationCells.isEmpty()) {
result = "kill";
}else{
result = "hit";
}
}
System.out.println(result);
return result;
}
}
public class SimpleDotComGame {
public static void main(String[] args) {
int numOfGuesses = 0;
GameHelper helper = new GameHelper();
SimpleDotCom theDotCom = new SimpleDotCom();
int randomNum = (int) (Math.random() * 5);
int[] locations = {randomNum, randomNum + 1, randomNum + 2};
theDotCom.setLocationCells(locations);
boolean isAlive = true;
while(isAlive == true) {
String guess = helper.getUserInput("enter a number");
String result = theDotCom.checkYourself(guess);
numOfGuesses++;
if(result.equals("kill")) {
isAlive = false;
System.out.println("You took " + numOfGuesses + " guesses");
}
}
}
}
报错显示为:Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method setLocationCells(ArrayList) in the type SimpleDotCom is not applicable for the arguments (int[])
at SimpleDotComGame.main(SimpleDotComGame.java:12)
求大佬解答