Question: Can someone answer without modifying the Coin.java and Player.java classes please? Heads or Tails Game This game is meant for two or more players. In

Can someone answer without modifying the Coin.java and Player.java classes please?

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 heads up or tails up. If the player guesses correctly, the player gets a point. If a player guesses incorrectly, then the player loses a point. The first player to score five points is the winner. You have been provided with a coin class and a player class (copy and paste the code into your own project). Do not modify the classes. Use these two classes to create a coin object and two player objects in an application that allows players to play the heads or tails game. If you need guidance as to how to create multiple classes in Eclipse please refer to the video example in Ch 7 Module in Moodle. The program (application) should allow the players to play against each other. The game should be played until one player wins. This program should have a main method that creates the objects and allows the game to continue until complete. The program should also contain a static method to display the round number, a static method to allow the player to make a guess, a static method to toss the coin, a static method to check the guess, a static method to display the points, and a static method to display the winner. **HINT: There will be a need to pass objects to the static methods. **

**Do not modify the classes.(Coin.java & Player.java)

**Please include comments. You are to submit three files for this assignment, Coin.java, Player.java, and the HeadsorTailsGame.java with your methods added.

The files Coin.java & Player.java are listed below.

Coin.java

import java.util.Random;

/** * Chapter 6 * Programming Challenge 14: Heads or Tails Game * The Coin class stores data for a coin that can be tossed. */

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 */ public String getSideUp() { return sideUp; } }

Player.java

import java.util.Random;

/** * Chapter 6 * Programming Challenge 14: Heads or Tails Game * The Player class simulates a player in the * Heads or Tails Game. */ public class Player { // Fields private String name; // The player's name private String guess; // The player's guess private int points; // The player's points /** * The constructor accepts an argument for * the player's name. */ public Player (String n) { name = n; guess = ""; points = 0; }

/** * The getName method returns * the name of the player. */ public String getName() { return name; } /** * The getGuess method returns the player's guess. */ public String getGuess() { return guess; } /** * The getName method returns * the number of points. */ public int getPoints() { return points; } /** * The setName method accepts an * argument for the name of the player. */ public void setName(String n) { name = n; } /** * The setGuess method accepts an * argument for the guess of the player. */ public void setGuess(String g) { guess = g; } /** * The setPoints method accepts an * argument for the player's points. */ public void setPoints(int p) { points = p; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Certainly Lets develop the HeadsOrTailsGamejava class using the Coinjava and Playerjava classes provided The purpose is to allow two players to play the game and well ensure not to modify the existing ... View full answer

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!