Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CoinRace {
- public static void main(String[] args) {
- final int GOAL = 3;
- int count1 = 0,count2 = 0;
- //count for each coin
- Coin coin1 = new Coin();
- Coin coin2 = new Coin();
- while ((count1 < GOAL) && (count2 < GOAL)) {
- coin1.flip();
- coin2.flip();
- count1 = ((coin1.isHeads()) ? count1 + 1 : 0);
- count2 = ((coin2.isHeads()) ? count2 + 1 : 0);
- System.out.println("Coin1 is :" + coin1.toString());
- System.out.println("Coin2 is :" + coin2.toString());
- System.out.println("");
- }
- if (count1 == GOAL) {
- System.out.println("Coin 2 WINS!\nIN " + coin2.getAttempt() + "ATTEMPTS");
- } else {
- if (count2 == GOAL) {
- System.out.println("Coin 1 WINS!\nIN " + coin1.getAttempt()+ " ATTEMPTS");
- } else {
- System.out.println("Its a tie");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement