File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ public class WordMatch implements GuessingGame {
2+ private String answer ;
3+ private int match ;
4+ private boolean fact = false ;
5+
6+ public WordMatch () {
7+ this .match = 0 ;
8+ }
9+
10+ @ Override
11+ public void setAnswer (String ans ) {
12+ answer = ans .toLowerCase ();
13+ }
14+
15+ @ Override
16+ public void guess (String s ) {
17+ String tmp = s .toLowerCase ();
18+ match =0 ;
19+ if (s .length ()!= answer .length ()){
20+ fact = true ;
21+ }
22+ else {
23+ for (int i = 0 ; i < answer .length (); i ++) {
24+ if (answer .charAt (i ) == tmp .charAt (i )) {
25+ match ++;
26+ }
27+ }
28+ }
29+ }
30+
31+ @ Override
32+ public String getOutput () {
33+ if (fact == true ){
34+ fact =false ;
35+ return "Length not match" ;
36+ }
37+ else if (match == answer .length ()){
38+ return "" ;
39+ }
40+ else {
41+ return "Match " + match ;
42+ }
43+ }
44+
45+ @ Override
46+ public boolean isWon () {
47+ if (match == answer .length ()){
48+ return true ;
49+ }
50+ return false ;
51+ }
52+
53+ @ Override
54+ public boolean isLost () {
55+ return false ;
56+ }
57+ }
You can’t perform that action at this time.
0 commit comments