- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMSWord.java
More file actions
Latest commit
117 lines (95 loc) · 2.65 KB
/
Copy pathMSWord.java
File metadata and controls
117 lines (95 loc) · 2.65 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
importjava.util.*;
/**
* MSWord beschreibt ein Wort und stellt eine Methode zum
* Bewerten eines Wortes zur Verfuegung.
*
* @author Goetz und Dominik
* @version 9.11
*/
publicclassMSWord
{
privateintrating;
privateStringword;
privateMaptable;
privateintdifficulty;
publicMSWord(Stringword)
{
// Instanzvariable initialisieren
this.word = word;
this.table = this.create_table();
this.rating = this.rating_method(word);
this.difficulty = this.set_difficulty();
}
publicintget_rating()
{
returnthis.rating;
}
publicStringget_word()
{
returnthis.word;
}
publicintget_difficulty(){
returnthis.difficulty;
}
publicintrating_method(Stringword)
{
intscore = 0;
word = word.toUpperCase();
// L = Length
intL = word.length();
// Re = Repetitions
intRe = 0;
// Ra = Rarity
intRa = 0;
for (inti = 0; i < L; i++)
{
//System.out.println(i);
charchr = word.charAt(i);
if (this.countLetter(word, chr) > 1){
Re += 1;
}
Stringtmp = word.substring(i,i+1);
Integertmp_2 = (Integer)this.table.get(tmp);
Ra += tmp_2;
}
score = L + Ra + Re;
returnscore;
}
privatestaticintcountLetter(Stringstr, charletter) {
str = str.toLowerCase();
letter = Character.toLowerCase(letter);
intcount = 0;
for (inti = 0; i < str.length(); i++) {
charcurrentLetter = str.charAt(i);
if (currentLetter == letter){
count++;
}
}
returncount;
}
publicMapcreate_table(){
Map<String, Integer> table = newHashMap<String, Integer>();
String[] parts;
Stringchr;
Integervalue;
In.open("ht.txt");
Stringtmp = In.readWord();
while(In.done()){
parts = tmp.split(";");
chr = parts[0];
value = Integer.valueOf(parts[1]);
table.put(chr, value);
// Out.println(chr + " : " + value);
tmp = In.readWord();
}
In.close();
returntable;
}
publicintset_difficulty(){
intdiff = 0;
intscore = this.get_rating();
// Diese Formel kann noch optimiert werden:
diff = 50 - (score / 100);
returndiff;
}
}