Skip to content

Commit e17f782

Browse files
committed
Addition of FlipCoin.java and renaming of classes to compile
1 parent 037eb06 commit e17f782

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

FlipCoin.java

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.company;
2+
3+
import java.util.Random;
4+
5+
public class FlipCoin {
6+
7+
public enum Coin {
8+
HEADS, TAILS;
9+
}
10+
11+
public enum Game {
12+
WIN, LOSE;
13+
}
14+
15+
private static Coin flip() {
16+
int random = new Random().nextInt(2);
17+
if (random == 0) {
18+
return Coin.HEADS;
19+
}
20+
return Coin.TAILS;
21+
}
22+
23+
public static boolean flipFor(Coin picked) {
24+
System.out.println("Flipping...");
25+
Coin landed = flip();
26+
System.out.printf("Landed %s%n", landed);
27+
return (landed == picked);
28+
}
29+
30+
public static void main(String[] args) {
31+
Coin chose = Coin.HEADS;
32+
System.out.printf("You chose %s%n", chose);
33+
Game game = flipFor(chose) ? Game.WIN : Game.LOSE;
34+
System.out.printf("You %s!%n", game);
35+
}
36+
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)