forked from srinathr91/TestJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResult.java
More file actions
101 lines (81 loc) · 1.45 KB
/
Result.java
File metadata and controls
101 lines (81 loc) · 1.45 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package DiceYatch;
public class Result {
public int getScore(Category kategory, int[] scores){
int sum = 0;
int score = 0;
int[] allScore = {0,0,0,0,0,0,0,0};
for(int i=0; i<5; i++){
allScore[scores[i]-1] += 1;
sum = sum + scores[i];
}
switch(kategory){
case Ones:
score = allScore[0]*1;
break;
case Twos:
score = allScore[1]*2;
break;
case Threes:
score = allScore[2]*3;
break;
case Fours:
score = allScore[3]*4;
break;
case Fives:
score = allScore[4]*5;
break;
case Sixes:
score = allScore[5]*6;
break;
case Sevens:
score = allScore[6]*7;
break;
case Eights:
score = allScore[7]*8;
break;
case AllSame:
{
for(int i=0; i<8; i++){
if(allScore[i]==5){
score = 50;
break;
}
else
score = 0;
}
break;
}
case AllDifferent:
{
for(int i=0; i<8; i++){
if(allScore[i]>1){
score = 0;
break;
}
else
score = 40;
}
break;
}
}
return score;
}
public Category getSuggestion(int[] scores){
int score = 0;
Category suggestion = null;
for(Category kategory : Category.values()){
int answer = this.getScore(kategory, scores);
if(score < answer){
suggestion = kategory;
score = answer;
}
if(answer == 50){
break;
}
if(answer == 40){
break;
}
}
return suggestion;
}
}