Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help in java! ALL files are below. Dealer.java (USE THESE FORMATS PLEASE. PlayGameClient.java AND Die.java ARE IN THE END AND ARE FULLY IMPLEMENTED.) /**
Need help in java! ALL files are below.
Dealer.java (USE THESE FORMATS PLEASE. PlayGameClient.java AND Die.java ARE IN THE END AND ARE FULLY IMPLEMENTED.)
/** * Dealer class for the game of Even Or Odd * * @author YOUR NAME * @version: 10/14/2017 */ public class Dealer { private Die die1; private Die die2; private final int SIDES = 6; /** * Constructor creates two Die objects */ public Dealer() { // TODO Project 2 System.out.println("In Dealer constructor - IMPLEMENT ME"); } /** * The shakeDiceCup method rolls both dice */ public void shakeDiceCup() { // TODO Project 2 System.out.println("In shakeDiceCup method - IMPLEMENT ME"); } /** * The calculateEvenOrOdd method returns the result of the dice roll * * @return EVEN if the sum of two dice roll is even, or ODD otherwise */ public String calculateEvenOrOdd() { // TODO Project 2 System.out.println("In calculateEvenOrOdd method - IMPLEMENT ME"); return "EVEN or ODD ???"; // THIS IS A STUB } /** * @return String representation of the dealer's roll */ public String toString() { return "The dealer rolled " + this.die1.getFace() + " " + this.die2.getFace() + " Result " + calculateEvenOrOdd(); } }
Player.java
import java.util.Random; /** * Player class for the game of Odd or Even * * @author: YOUR NAME * @version: 10/14/2017 */ public class Player { private String name; private String guess; private int points; /** * Constructor sets the name to the given playersName, * guess is set to empty string, and points to 0 * * @param playerName The player's name */ public Player(String playerName) { // TODO Project 2 System.out.println("In Player constructor - IMPLEMENT ME"); } /** * The makeGuess method causes the player to guess either EVEN or ODD * Creates a random object and utilizes nextBoolean method */ public void makeGuess() { // TODO Project 2 System.out.println("In makeGuess method - IMPLEMENT ME"); } /** * The addPoint method adds one point to the player's current balance */ public void addPoint() { // TODO Project 2 System.out.println("In addPoint method - IMPLEMENT ME"); } /** * Accessor method * * @return the player's name field */ public String getName() { // TODO Project 2 return "name ???"; // THIS IS A STUB } /** * Accessor method * * @return the value of the guess field */ public String getGuess() { // TODO Project 2 return "guess ???"; // THIS IS A STUB } /** * Accessor method * * @return the value of the points field */ public int getPoints() { // TODO Project 2 return 0; // THIS IS A STUB } /** * @return the String representation of the content of the player's object: * only players name and the numbers of points are given */ public String toString() { // TODO Project 2 return "toString ???"; // THIS IS A STUB } }
PlayGame.java
import java.util.Scanner; /** * Guessing game of OddOrEven. * * @author: YOUR NAME * @version: 10/14/2017 */ public class PlayGame { private Player player1; private Player player2; private Dealer dealer; private final int MAX_ROUNDS = 5; /** * Constructor * * @param player1Name name of the player 1 as entered by the user * @param player2Name name of the player 2 as entered by the user */ public PlayGame(String player1Name, String player2Name) { // Create the dealer this.dealer = new Dealer(); // Create the two players this.player1 = new Player(player1Name); this.player2 = new Player(player2Name); // TODO Project 2 System.out.println("In PlayGame constructor - IMPLEMENT ME"); // // Play MAX_ROUNDS // For each round: // a. asks dealer to shake the dice cup // b. asks each player for their guess // c. calls roundResults method to display the round statistics } /** * The roundResults method determines the results of the current round * Displays the dealer's data and checks each player's guess * against the dealer's result. Awards a point to a player if (s)he guessed correctly. * Displays the appropriate message(s) */ private void roundResults() { // TODO Project 2 System.out.println("In roundResults method - IMPLEMENT ME"); // show the dice values rolled by the dealer // check each player guess and award points } /** * The displayGrandWinner method displays the game's grand winner or a tie */ public void displayGrandWinner() { System.out.println(); System.out.println(" *** Game over. Here are the results ***"); // TODO Project 2 System.out.println("In displayGrandWinner method - IMPLEMENT ME"); } }
Die.java
import java.util.Random; /** * This is service class that allows to create Die objects * * @version: 10/07/17 */ public class Die { // These two statements declare two instance variables: numberOfSides and face // The numberOfSides field holds the number of sides that the die has. // The face field holds the value of face that was last rolled private int numberOfSides; private int face; // This constant holds the default value of number of sides public static final int DEFAULT_NUMBER_OF_SIDES = 6; /** * The default constructor creates the die object with the DEFAULT_NUMBER_OF_SIDES * and performs the initial roll of the die * */ public Die() { // This is a default constructor (does not take any parameter). // Sets the numberOfSides to the default value. // The value of the face field is generated and set // by the roll method setNumberOfSides(DEFAULT_NUMBER_OF_SIDES); roll(); } /** * The secondary constructor creates the die object and performs the initial * roll of the die * * @param numberOfSides the number of sides for this die */ public Die(int numberOfSides) { // This is a secondary constructor (takes a parameter). // Notice that the constructor has a parameter for // the number of sides that is passed by the client. Since the input must // be validated constructor calls the mutator method setNumberOfSides to set the value // of the numberOfSides field. The value of the face field is generated and set // by the roll method setNumberOfSides(numberOfSides); roll(); } /** * Mutator method * Validates that the initialNumberOfSides is either: * four, six, eight, ten, twelve, or twenty numberOfSides. * If not sets numberOfSides to the default value * * @param initialNumberOfSides */ public void setNumberOfSides(int initialNumberOfSides) { // This is a mutator method for the numberOfSides field. // It validates the input first. If the input is valid // uses it to set the value of numberOfSides field. If the input // is invalid sets the numberOfSides field to DEFAULT_NUMBER_OF_SIDES switch (initialNumberOfSides) { case 4: case 6: case 8: case 10: case 12: case 20: this.numberOfSides = initialNumberOfSides; break; default: this.numberOfSides = DEFAULT_NUMBER_OF_SIDES; break; } } /** * Accessor method * * @return the current value of numberOfSides */ public int getNumberOfSides() { return this.numberOfSides; } /** * Mutator method * Generates randomly the face of the roll of the die */ public void roll() { // This is a mutator method for the face field. First it creates a Random object // which is referenced by the rand variable. It uses the rand object to get // a random number that is in the appropriate range for this particular die. // For example, if the field numberOfSides is set to 6, field face will be set to an integer // in the range of 1 through 6 Random rand = new Random(); this.face = rand.nextInt(this.numberOfSides) + 1; } /** * Accessor method * * @return the current face of the roll of the die */ public int getFace() { return this.face; } /** * toString method * @return the string representation of the Die object */ public String toString() { return "has " + this.numberOfSides + " sides, its face is " + this.face; } /** * equals method * @param other Die object that this objects is being compared with * @return true if this and other objects are the same */ public boolean equals(Die other) { return (this.numberOfSides == other.numberOfSides) && (this.face == other.face); } }
PlayGameClient.java
import java.util.Scanner; /** * CLIENT CLASS for guessing game of OddOrEven. * * @author: YOUR NAME * @version: 10/14/2017 */ public class PlayGameClient { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); do { // Get the players names System.out.println("Enter the name of the first player"); String player1Name = keyboard.nextLine(); System.out.println("Enter the name of the second player"); String player2Name = keyboard.nextLine(); // Start and play the game PlayGame game = new PlayGame(player1Name, player2Name); // Display the overall winner game.displayGrandWinner(); System.out.println(" Would you like to play again? (yeso)"); } while (keyboard.nextLine().equalsIgnoreCase("yes")); System.out.println("Goodbye!"); } }
Implement a solution to the problem described below. Your work must include the following: Your version of the PlayGame.java, Player.java, Dealer.java Output of your program that shows multple runs that test various scenarios o include as many comments as are necessary to describe what the given code segment is doing o make sure that your code is formatted properly .Please make sure to include vour name in each file that you are submitting BEFORE STARTING PLEASE READ THE PROBLEM DESCRIPTION AND THE INSTRUCTIONS CAREFULLY blem Descri Guessing game of OddOrEven is a game where a dealer uses a cup to roll two six-sided dice. The cup is placed upside down on a table so that the value of the dice is concealed. Players then have to guess if the sum of the dice values id ODD or EVEN. We will develop a program that simulates a variation of this game. The simulated game will have a dealer and two players. The players will simply guess whether the sum of the dice values is odd or even. One point will be awarded to each player who correctly guesses the result. The game will play for five rounds, and the player with the most points is the grand winner. The tie is also possible. In this program we will utilize the Die class that we studied before. We will create two objects of this class to represent two six-sided dice In addition, we will write the following classes: Dealer class: we will create an instance of this class to represent the dealer. It will have the ability to roll the dice, and report whether the total dice value is odd or even Player class: we will create two objects of this class to represent the players. Instances of the Player class can store the playes name, players guess made between ODD or EVEN, and the running total of awarded points PlayGame class: its constructor creates all the necessary elements for the game, plays the round, and displays the running results and the final results PlayGameClient class: this class has main for this application and is fully implemented. See the provided UML diagram, sample run and the javaDoc comments throughout the classes
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started