-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathScrabble.java
More file actions
54 lines (47 loc) · 1.29 KB
/
Scrabble.java
File metadata and controls
54 lines (47 loc) · 1.29 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
package com.booleanuk;
import java.util.HashMap;
public class Scrabble {
String word;
public Scrabble(String word) {
this.word = word;
}
public int score() {
HashMap<Character, Integer> values = new HashMap<>();
values.put('A', 1);
values.put('B', 3);
values.put('C', 3);
values.put('D', 2);
values.put('E', 1);
values.put('F', 4);
values.put('G', 2);
values.put('H', 4);
values.put('I', 1);
values.put('J', 8);
values.put('K', 5);
values.put('L', 1);
values.put('M', 3);
values.put('N', 1);
values.put('O', 1);
values.put('P', 3);
values.put('Q', 10);
values.put('R', 1);
values.put('S', 1);
values.put('T', 1);
values.put('U', 1);
values.put('V', 4);
values.put('W', 4);
values.put('X', 8);
values.put('Y', 4);
values.put('Z', 10);
int total = 0;
String upperWord = word.toUpperCase();
System.out.println(upperWord);
for (char letter : upperWord.toCharArray()) {
if (values.containsKey(letter)) {
int value = values.get(letter);
total += value;
}
}
return total;
}
}