Question: pls use java as easy as possible, since I am a first-year students P1: First to One Game This game is meant for two or

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

P1: First to One Game This game is meant for two or more players. In the game, each player starts out with 50 points, as each player takes a turn rolling the dice; the amount generated by the dice is subtracted from the players points. The first player with exactly one point remaining wins. If a players remaining points minus the amount generated by the dice results in a value less than one, then the amount should be added to the players points.

Write a new DicePlayer class to simulate the players. The DicePlayer class should have fields for the player's name and points as well as appropriate constructor, accessor and mutator methods.

Write a main method program that simulates the game being played by two players. Use the Die class you wrote for Assignment 05 - 4 (or use the file provided in the Assignment 05 - 4 Solutions). the Dia class is shown below:

Die java:

import java.util.Random;

/** The Die class simulates a six-sided die. */

public class Die { private int sides; // Number of sides private int value; // The die's value /** The constructor performs an initial roll of the die. @param numSides The number of sides for this die. */ public Die(int numSides) { sides = numSides; roll(); } /** The roll method simlates the rolling of the die. */ public void roll() { // Create a Random object. Random rand = new Random(); // Get a random value for the die. value = rand.nextInt(sides) + 1; } /** getSides method @return The number of sides for this die. */ public int getSides() { return sides; } /** getValue method @return The value of the die. */ public int getValue() { return value; } }

Dice game:

import java.util.Random; // Needed for Random class

/** This program demonstrates a solution to the Dice Game programming challenge. */

public class DiceGame { public static void main(String[] args) { // Named constants final int NUM_SIDES = 6; // The number of sides on the die // Variables int compValue = 0; // To hold the computer's dice value int userValue = 0; // To hold the user's dice value int compGames = 0; // To hold the number of games won by the computer int userGames = 0; // To hold the number of games won by the user int tiedGames = 0; // To hold the number of tied games // Create a Die object for the computer. Die computerDie = new Die(NUM_SIDES); // Create a Die object for the user. Die userDie = new Die(NUM_SIDES); // Play ten rounds of the dice game. for (int round = 1; round <= 10; round++) {

// Get the computer's die value. computerDie.roll(); compValue = computerDie.getValue(); // Get the user's die value. userDie.roll(); userValue = userDie.getValue(); // Determine the winner of this round. if (compValue != userValue) { if (compValue > userValue) // The computer wins this round. compGames++; else // The user wins this round. userGames++; } else // This round has ended in a tie. tiedGames++; } // Display the results. System.out.println("Computer...." + compGames); System.out.println("User........" + userGames); System.out.println("Ties........" + tiedGames); // Determine the grand winner. if (compGames > userGames) // The computer won the most games. System.out.println("The computer is the grand winner!"); else if (compGames < userGames) // The user won the most games. System.out.println("The user is the grand winner!"); else // The game was a tie. System.out.println("The game has ended in a tie!"); } }

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!