-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordGame.java
More file actions
76 lines (63 loc) · 1.84 KB
/
Copy pathWordGame.java
File metadata and controls
76 lines (63 loc) · 1.84 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
69
70
71
72
73
74
75
76
//import java.util.Arrays;
public class WordGame {
public static void main (String[] args) {
char[] tenPoints = {'j', 'q', 'x', 'z'};
char[] fivePoints = {'k', 'v'};
char[] onePoint = new char[52];
int i = 0;
for (char ch = 'a', cH = 'A'; ch <= 'z'; ch++, cH++) {
onePoint[i] = ch;
onePoint[26+i] = cH;
i++;
}
/*System.out.println(Arrays.toString(tenPoints));
System.out.println(Arrays.toString(fivePoints));
System.out.println(Arrays.toString(onePoint));*/
char[] testArray = new char[] {'a', 'r', 't', 'f', 'z'};
System.out.println(playGame(testArray, tenPoints, fivePoints, onePoint));
testArray = new char[] {'A'};
System.out.println(playGame(testArray, tenPoints, fivePoints, onePoint));
testArray = new char[] {'#'};
System.out.println(playGame(testArray, tenPoints, fivePoints, onePoint));
testArray = new char[] {'A', 'k', 'j'};
System.out.println(playGame(testArray, tenPoints, fivePoints, onePoint));
}
public static int playGame (char[] a, char[] ten, char[] five, char[] one) {
int sum = 0;
boolean testOtherArray = true;
for (int i = 0; i < a.length; i++) {
if (testOtherArray) {
for (char ch10 : ten) {
if (a[i] == ch10) {
sum += 10;
testOtherArray = false;
break;
}
}
}
if (testOtherArray) {
for (char ch5 : five) {
if (a[i] == ch5) {
sum += 5;
testOtherArray = false;
break;
}
}
}
if (testOtherArray) {
for (char ch1 : one) {
if (a[i] == ch1) {
sum++;
testOtherArray = false;
break;
}
}
}
if (testOtherArray) {
sum += 0;
}
testOtherArray = true;
}
return sum;
}
}