public class CoinGame { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Player jack = new Player(.75F); Player jill = new Player(3); // jill = jack; System.out.println("OK, here we go"); while (!(jack.reachedGoal() || jill.reachedGoal())){ System.out.println("flipping coins"); jack.flip(); jill.flip(); } if (jack.getHeads() > jill.getHeads()){ System.out.println("congratulations Jack"); } else if (jill.getHeads() > jack.getHeads()){ System.out.println("congratulations Jill"); } else System.out.println("tie game"); } } class Player{ static final int GOAL = 10; private int heads; // instance variable Player(){ // call the other constructor this(0); } Player(int handicap){ heads = handicap; } Player(float fraction){ heads = Math.round(fraction*GOAL); System.out.println("setting heads to "+ heads); } public int getHeads(){ return heads; } public void flip(){ double x = Math.random(); if(x > 0.5){ heads++; } } public boolean reachedGoal(){ return (heads >= GOAL); } }