-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotcom_game.java
More file actions
44 lines (37 loc) · 1.06 KB
/
Copy pathdotcom_game.java
File metadata and controls
44 lines (37 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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);
// String testResult = "failed";
// if (result.equals("hit")) {
// testResult = "passed";
// }
// System.out.println(testResult);
}
}
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;
}
}