Question: Java: This game is meant for two or more players. In this game, the players take turns flipping a coin. Before the coin is flipped,
Java:
This game is meant for two or more players. In this game, the players take turns flipping a coin. Before the coin is flipped, players should guess if the coin will land face up or face down. If a player guesses correctly, then that player is awarded a point. If a player guesses incorrectly, then that player will lose a point. The first player to score five points is the winner.
Write a program that simulates the game being played by two players. The Coin class should have the following field: A String named sideUp. The sideUp field will hold either heads or tails indicating the side of the coin that is facing up. The Coin class should have the following methods: A no-arg constructor that randomly determines the side of the coin that is facing up (heads or tails) and initializes the sideUp field accordingly. A void method named toss that simulates tossing the coin. When the toss method is called, it randomly determines the side of the coin that is facing up (heads or tails) and sets the sideUp field accordingly. A method named getSideUp that returns the value of the sideUp field.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
