-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWords.java
62 lines (55 loc) · 1.25 KB
/
Words.java
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
58
59
60
61
62
package lab1;
public class Words {
private String word1;
private String word2;
private String originWord = null;
private enum postfix {ing, ied, ies, es, s, d}
public Words(String word1, String word2) {
this.word1 = word1;
this.word2 = word2;
}
public Words (){}
public void setWord1(String word1){
this.word1 = word1;
}
public void setWord2(String word2) {
this.word2 = word2;
}
public String getOriginWord(){
return originWord;
}
// test whether two words share the same meaning
public boolean isSame(){
int len1 = word1.length();
int len2 = word2.length();
String s1 = null,s2 = null;
boolean tmp = false;//len1 not change?
if(len1>len2)
len1 = len2;
else
tmp = true;
s1 = word1.substring(0, len1);
s2 = word2.substring(0, len1);
while(!s1.equals(s2)&&len1>0){
s1 = s1.substring(0, --len1);
s2 = s2.substring(0, len1);
}
if(len1 == 0)
return false;
String post = null;
if(tmp){
post = word2.substring(len1);
originWord = word1;
}
else{
post = word1.substring(len1);
originWord = word2;
}
tmp = false;
for(postfix a : postfix.values()){
if(post!=null&&post.equals(a.toString()))
tmp = true;
}
return tmp;
}
}