Oque tem de errado com este código. Esse código é pra simular um Batalha Naval. Dentro de um vetor, e retornar se o barco afundou, se acertou ou se somente errou o tiro.
Classe: 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);
}
}
}
Classe: SimpleDotCom
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;
}
}
Alguem sabe porque da esse erro?
13: class, interface, or enum expected