-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathScrabble.java
More file actions
44 lines (28 loc) · 1 KB
/
Scrabble.java
File metadata and controls
44 lines (28 loc) · 1 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
package com.booleanuk;
import java.util.HashMap;
public class Scrabble {
private String word;
private static HashMap<Character, Integer> Points;
static {
Points = new HashMap<>();
for (char letter : "AEIOULNRST".toCharArray()) Points.put(letter, 1);
for (char letter : "DG".toCharArray()) Points.put(letter, 2);
for (char c : "BCMP".toCharArray()) Points.put(c, 3);
for (char letter : "FHVWY".toCharArray()) Points.put(letter, 4);
Points.put('K', 5);
for (char letter : "JX".toCharArray()) Points.put(letter, 8);
for (char letter : "QZ".toCharArray()) Points.put(letter, 10);
}
public Scrabble(String word) {
this.word = word.toUpperCase();
}
public int score() {
int totalPoints = 0;
for (char letter : word.toCharArray()) {
if (Points.containsKey(letter)) {
totalPoints = totalPoints + Points.get(letter);
}
}
return totalPoints;
}
}