public class CoinGame { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Player jack = new Player(); Player jill = new Player(); // jill = jack; System.out.println("OK, here we go"); while (!(jack.reachedGoal() || jill.reachedGoal())){ System.out.println("flipping coins"); jack.multipleFlip(6); System.out.println("Jack " + jack.getHeads()); jill.multipleFlip(5); System.out.println("Jill " + jill.getHeads()); } 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 = 100; 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 we are dumb enough to put in a local variable // with the same name as the instance variable, we // actually need "this.heads" to distinguish that we // want to increment the instance variable // int heads = -100; if(x > 0.5){ heads++; // or, heads++; } } public void multipleFlip(int n){ for (int i=0; i= GOAL); } }