10-18-2013

posted Oct 18, 2013, 9:14 AM by Samuel Konstantinovich   [ updated Oct 18, 2013, 9:25 AM ]

Complete this over the weekend, and store it in a folder HW6 on your dropbox.


Create a class CoinGame in CoinGame.java

The CoinGame class will play a game between two players, each represented by a BankAccount. The CoinGame class should also have two instance variables represneting two Coins.

Each turn works as follows:

  1. Create the “pot” by withdrawing a random amount from both bank accounts (the same for each) and storing it in the game class. This amount cannot exceed the smaller of the two balances.
  2. The coins should be flipped
  3. If it’s two heads, player 1 (BankAccount 1) wins and gets the pot.
  4. If it’s two tails, player 2 (BankAccount 2) wins and gets the pot.
  5. Otherwise, the money stays in the pot.

You will need the following instance variables in CoinGame:

  • Two BankAccounts
  • Two Coins
  • The pot
  • Anything else you need

Write a method public void turn() which plays out a single turn as described above.

You will also need methods to get the current BankAccount values so you can see who is winning.

Now write a method public void play(int n) which will play the game for n turns.

Comments