-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathScrabble.java
More file actions
68 lines (58 loc) · 1.48 KB
/
Scrabble.java
File metadata and controls
68 lines (58 loc) · 1.48 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
package com.booleanuk;
public class Scrabble {
private final String word;
public Scrabble(String word) {
this.word = word;
}
public int score() {
int total = 0;
String upperCaseString = word.toUpperCase();
for (int i = 0; i <upperCaseString.length(); i++) {
char ch = upperCaseString.charAt(i);
switch(ch) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'L':
case 'N':
case 'R':
case 'S':
case 'T':
total += 1;
break;
case 'D':
case 'G':
total += 2;
break;
case 'B':
case 'C':
case 'M':
case 'P':
total += 3;
break;
case 'F':
case 'H':
case 'V':
case 'W':
case 'Y':
total += 4;
break;
case 'K':
total += 5;
break;
case 'J':
case 'X':
total += 8;
break;
case 'Q':
case 'Z':
total += 10;
break;
default:
}
}
return total;
}
}