CS 111 - Introduction to Computer Science
Homework #7

Due at the beginning of class 21.

1. Average Pig Turns:  In file AveragePigTurns.java, implement this specificationIn addition, while Scanner input and System.out output will take place only in the main method, all solitaire game simulation and average turn computation should take place in a method getAverageTurns that takes an integer parameter for the number of games to simulate, and returns a double-precision floating-point average turn computation.  The main method will read the desired number of simulations, call method getAverageTurns with that number, and report the returned number in the specified format.  Note: You'll want to copy your PigSolitaireGame.java code as a starting point.

2. Two-Computer-Player Pig: In file PigComputerGame.java, implement this specificationNote: You'll want to copy your PigSolitaireGame.java code as a starting point.  Hint: There is little that you need to change from PigSolitaireGame.java if you approach this modularly.  For each turn, you'll alternate between two players.  You'll need to keep track of the two player scores in two variables.  However, you can keep the same core turn code from PigSolitaireGame.java if (1) before the turn, you copy the current player's score into your score variable from your earlier code, (2) after the turn, copy the new score back into the current player's score variable, and then (3) change a variable that keeps track of which player is the current player.


3. Pig First Player Advantage: In file PigAdvantage.java, implement this specificationIn addition, while Scanner input and System.out output will take place only in the main method, all solitaire game simulation and computation of the first player win probability estimate should take place in a method getAdvantage that takes an integer parameter for the number of games to simulate, and returns a double-precision floating-point first player win probability.  The main method will read the desired number of simulations, call method getAdvantage with that number, and report the returned number in the specified format.  Note: You'll want to copy your PigComputerGame.java code as a starting point.

Rubric: (20 points total)