-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathWordMatch.java
More file actions
57 lines (51 loc) · 1.16 KB
/
WordMatch.java
File metadata and controls
57 lines (51 loc) · 1.16 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
45
46
47
48
49
50
51
52
53
54
55
56
57
public class WordMatch implements GuessingGame {
private String answer ;
private int match;
private boolean fact = false;
public WordMatch() {
this.match = 0;
}
@Override
public void setAnswer(String ans) {
answer = ans.toLowerCase();
}
@Override
public void guess(String s) {
String tmp = s.toLowerCase();
match =0;
if(s.length()!= answer.length()){
fact = true;
}
else {
for (int i = 0; i < answer.length(); i++) {
if (answer.charAt(i) == tmp.charAt(i)) {
match++;
}
}
}
}
@Override
public String getOutput() {
if(fact == true){
fact =false;
return "Length not match";
}
else if(match == answer.length()){
return "";
}
else {
return "Match " + match;
}
}
@Override
public boolean isWon() {
if(match == answer.length()){
return true;
}
return false;
}
@Override
public boolean isLost() {
return false;
}
}