Part 1: Coin Toss Game
In this you will create a program that models coin objects. The coins
will be used in a coin toss game to win a sum of money equal to double the
amount the user bets before tossing the coin. The user will also enter their guess
as either 0 for heads or 1 for tails (both as integers).
Your solution should consist of two classes:
1. The Coin class. Each coin will be initialized with a bet value and will contain
two methods (plus a constructor):
flip() : tosses the coin and returns either a 0 for heads or a 1 for tails. You can
use the Math class from the java.util package to generate random numbers
and simulate a coin toss. The Math.random() method returns a random
floating point number between 0.0 and 1.0. You could call it "heads" if the
number is greater than 0.5, and tails otherwise.
getPrizeValue(): returns two times the initial bet value for this particular coin.
2. The GamePlayer class that prompts the user (via a main method) to enter
their bet amount in dollars and then choose either heads or tails. The
GamePlayer should then create a new Coin with the user’s bet amount, flip
the coin and return a statement either saying that the user lost or that the
user won, and the amount of the prize . Prizes should be formatted as
dollar values to two decimal places.
Sample Output (win):
Enter your initial bet value for the coin toss to the nearest dollar
20
Now enter your guess, enter 0 for heads or 1 for tails
1
You won! Your prize amount is:
$40.00
Sample Output (loss):
Enter your initial bet value for the coin toss to the nearest dollar
30
Now enter your guess, enter 0 for heads or 1 for tails
1
You lost...please play again