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