forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlipCoin.java
36 lines (29 loc) · 813 Bytes
/
FlipCoin.java
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
package com.company;
import java.util.Random;
public class FlipCoin {
public enum Coin {
HEADS, TAILS;
}
public enum Game {
WIN, LOSE;
}
private static Coin flip() {
int random = new Random().nextInt(2);
if (random == 0) {
return Coin.HEADS;
}
return Coin.TAILS;
}
public static boolean flipFor(Coin picked) {
System.out.println("Flipping...");
Coin landed = flip();
System.out.printf("Landed %s%n", landed);
return (landed == picked);
}
public static void main(String[] args) {
Coin chose = Coin.HEADS;
System.out.printf("You chose %s%n", chose);
Game game = flipFor(chose) ? Game.WIN : Game.LOSE;
System.out.printf("You %s!%n", game);
}
}