-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiceGame.java
More file actions
39 lines (29 loc) · 1.25 KB
/
Copy pathDiceGame.java
File metadata and controls
39 lines (29 loc) · 1.25 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
import java.util.Scanner;
public class DiceGame {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
double expectationOfGunnar = getExpectationFromDice();
double expectationOfEmma = getExpectationFromDice();
if (expectationOfGunnar > expectationOfEmma) {
System.out.println("Gunnar");
} else if (expectationOfGunnar < expectationOfEmma) {
System.out.println("Emma");
} else {
System.out.println("Tie");
}
}
private static double getExpectationFromDice() {
// expectation of 1st dice
int side1 = sc.nextInt();
int side2 = sc.nextInt();
double expectationOfDieOne = ((double) (side2 + side1) / 2); // this is the average value from the sides divided by
// the
// probability of landing on it (num of sides)
// expectation of 2nd dice
int side3 = sc.nextInt();
int side4 = sc.nextInt();
double expectationOfDieTwo = ((double) (side4 + side3) / 2) ; // this is the average value from the
// sides divided by the
return expectationOfDieOne + expectationOfDieTwo;
}
}