Question: pls use java as easy as possible, since I am a first-year student P2: Heads or Tails Game This game is meant for two or

pls use java as easy as possible, since I am a first-year student

P2: Heads or Tails Game 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 new CoinPlayer class to simulate the players of this coin game. This CoinPlayer class should have fields for the player's name, guess and points as well as the appropriate constructor, accessor and mutator methods. The CoinPlayer class should also have a method called makeGuess which will randomly select a guess of heads or tails for the player (to be used to create a computer player when not enough human players are available).

Write a main method program that simulates the game being played by two players (one a human player, the other a computer player). Use the Coin class provided below.

import java.util.Random;

/** Coin class */

public class Coin { private String sideUp; // The side facing up /** The constructor randomly sets the side of the coin that is facing up: heads or tails. */ public Coin() { // Call the toss method to set the // initial state of sideUp. toss(); } /** The toss method simulates the tossing of the coin. After the method executes, the sideUp field will be randomly set to either "heads" or "tails". */ public void toss() { // Create a random object. Random rand = new Random(); // Get a random value, 0 or 1. int value = rand.nextInt(2); // Set the value of sideUp. // 0 = "heads" or 1 = "tails" if (value == 0) sideUp = "heads"; else sideUp = "tails"; } /** The getSideup method @return The side of the coin facing up. */ public String getSideUp() { return sideUp; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!