-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scrabble.java
40 lines (36 loc) · 1.07 KB
/
Scrabble.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
class Scrabble {
int score = 0;
Scrabble(String word) {
for (int i = 0; i < word.length(); i++) {
score += getLetterScore(word.charAt(i));
}
}
int getScore() {
return score;
}
int getLetterScore(char letter) {
letter = Character.toLowerCase(letter);
if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u' || letter == 'l' || letter == 'n' || letter == 'r' || letter == 's' || letter == 't') {
return 1;
}
if (letter == 'd' || letter == 'g') {
return 2;
}
if (letter == 'b' || letter == 'c' || letter == 'm' || letter == 'p') {
return 3;
}
if (letter == 'f' || letter == 'h' || letter == 'v' || letter == 'w' || letter == 'y') {
return 4;
}
if (letter == 'k') {
return 5;
}
if (letter == 'j' || letter == 'x') {
return 8;
}
if (letter == 'q' || letter == 'z') {
return 10;
}
return 0;
}
}