[SOLVED] IN JAVA: This game is meant for two or more players., Each player starts out with 50 points, as each player takes a turn rolling the dic…..

We offer all "help with my paper" services e.g. Custom essay writing, Dissertation writing help, Research paper writing, and Term paper writing services at affordable prices. We cover all your paper help needs 24/7.
Get started Order in Chat
10+
Years of experience
53k
Papers prepared
4.8/5
Customer satisfaction

IN JAVA: This game is meant for two or more players., 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 player’s points. The first player with exactly one point remaining wins. If a player’s remaining points minus the amount generated by the dice results in a value less than one, then the amount should be added to the player’s points. (As a alternative, the game can be played with a set number of turns. In this case the player with the amount of points closest to one, when all rounds have been played, wins.) Write a program that simulates the game being played by two players. Use the Die class that was presented in Chapter 6 to simulate the dice. Write a Player class to simulate the player. Enter the player’s names and display the die rolls and the totals after each round.

THIS IS THE DIE CLASS: please complete entire program and upload screenshot of output along with the answer.

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;
}
}

OUTPUT SHOULD BE SOMETHING LIKE:

———————————

Round 1:

player1 rolled a 6

player2 rolled a 4

player1 has 44 points

player2 has 46 points

player1 wins.

———————————-

Expert Answer

 

import java.io.*;
import java.util.*;

class Die
{
private int sides;
private int value;

public Die(int numSides)
{
sides = numSides;
roll();
}

public void roll()
{
// Create a Random object.
Random rand = new Random();

// Get a random value for the die.
value = rand.nextInt(sides) + 1;
}

public int getSides()
{
return sides;
}

public int getValue()
{
return value;
}
}

class Player{

private String name;
private int score;
private Die die;
public Player(String a){
name = a;
score = 50;
die = new Die(6);
}
public int roll(){
die.roll();
return (die.getValue());
}
public void modifyScore(int a){
if ((score – a) < 1)
score = score + a;
else
score = score -a;
}
public int getScore(){
return score;
}
public String getName(){
return name;
}

}

public class DemoGame {
public static void main(String[] args){
int s1,s2;
int diff1, diff2;
String name1 , name2;
Scanner sc = new Scanner(System.in);
System.out.println(“Enter Player 1 Name:”);
name1 = sc.next();
System.out.println(“Enter Player 2 Name:”);
name2 = sc.next();

Player p1 = new Player(name1);
Player p2 = new Player(name2);
int count = 1;
while (p1.getScore() != 1 && p2.getScore() != 1){
System.out.println(“—————————–“);
System.out.println(“Round ” + count + “:”);
s1 = p1.roll();
p1.modifyScore(s1);
System.out.println(p1.getName() + ” rolled a ” + s1);
diff1 = p1.getScore() – 1;
s2 = p2.roll();
p2.modifyScore(s2);
System.out.println(p2.getName() + ” rolled a ” + s2);
diff2 = p2.getScore() – 1;
System.out.println(p1.getName() + ” has ” + p1.getScore() + ” points”);
System.out.println(p2.getName() + ” has ” + p2.getScore() + ” points”);
if (diff1 == diff2){
System.out.println(“It is a tie”);
}
else {
if (diff1 < diff2){
System.out.println(p1.getName() +” wins”);
}
else {
System.out.println(p2.getName() + ” wins”);
}
}
count++;
}

}
}

 

Guarantees
What you will get
Professional writers
Our strict writer selection process ensures that only professional college essay writers, subject-matter experts with MA and higher degrees work on your orders.
100% confidentiality
Your personal data is in no way shared with third parties. Writers also do not have access to it. We require your email address for login and notification purposes only.
Affordable prices
My Paper Support is a cheap essay writing service offering the best balance between quality and price. Regular customers enjoy special discounts, deals, and other perks.
Original content
We guarantee plagiarism-free work and that your custom college papers will pass Turnitin. Since Turnitin saves all files, we check papers with Copyleaks and Copyscape.
NEVER TRIED A WRITING SERVICE BEFORE?
Here's why students opt for our essay writing company
Hiring a qualified paper writer is one of the best ways to improve your academic writing skills and do better in class.
Lack of time
GPA concerns
Tough topic
Trust issues
When 24 hours is not enough
Most of the students approach us when they are overworked, work in parallel with studies, do internships, and do not have enough time for everything. So, we are their problem solvers and even offer super short 1-3 hour deadlines for emergency requests.
Quick turnaround time. You will receive your
paper before the deadline.
Get started Order in Chat
When grades need a boost
Our experts can help improve your performance and earn you a maximum grade. This is made possible due to the strict quality control, writers' rating system, adherence to requirements, proper formatting, access to all academic databases, credible and up-to-date sources.
Only credible sources. Your work will be based on reputable
sources that provide factual information on the topic.
Get started Order in Chat
When getting help is the best option
Sometimes you can get stuck on a topic, may not be able to find adequate sources, or access to such sources can be too expensive. That's when extra help might be the most valuable tactic to save nerves and meet the deadline with a high-quality paper.
All copyrights belong to you. You can use the delivered
samples in any way you choose.
Get started Order in Chat
When reliable service is needed
We cover almost all types of work, regardless of their complexity. That is why our service is used by college, high school, undergraduate, MA, and Ph.D. students from the USA, UK, and other regions. Besides, we partner with safe payment methods and provide a transparent refund policy.
Money-back guarantee. We will return your money
if you are not satisfied with the result.
Get started Order in Chat
Calculate the price
Make an order in advance and get the best price
Pages (550 words)
$0.00
*Price with a welcome 15% discount applied.
Pro tip: If you want to save more money and pay the lowest price, you need to set a more extended deadline.
We know how difficult it is to be a student these days. That's why our prices are one of the most affordable on the market, and there are no hidden fees.

Instead, we offer bonuses, discounts, and free services to make your experience outstanding.
How it works
Receive a 100% original paper that will pass Turnitin from a top essay writing service
step 1
Upload your instructions
Fill out the order form and provide paper details. You can even attach screenshots or add additional instructions later. If something is not clear or missing, the writer will contact you for clarification.
Pro service tips
How to get the most out of your experience with My Paper Support
One writer throughout the entire course
If you like the writer, you can hire them again. Just copy & paste their ID on the order form ("Preferred Writer's ID" field). This way, your vocabulary will be uniform, and the writer will be aware of your needs.
The same paper from different writers
You can order essay or any other work from two different writers to choose the best one or give another version to a friend. This can be done through the add-on "Same paper from another writer."
Copy of sources used by the writer
Our college essay writers work with ScienceDirect and other databases. They can send you articles or materials used in PDF or through screenshots. Just tick the "Copy of sources" field on the order form.
Testimonials
See why 20k+ students have chosen us as their sole writing assistance provider
Check out the latest reviews and opinions submitted by real customers worldwide and make an informed decision.
Nursing
Thank you for the outstanding work .
Customer 452635, June 5th, 2022
Social Work and Human Services
Excellent Work!
Customer 452587, November 30th, 2021
Nursing
Writer did an excellent job! Thank you.
Customer 452693, January 14th, 2022
Nursing
A-1 service every single time!!!
Customer 452453, July 27th, 2021
Medicine
Thank you for the great services
Customer 452635, April 24th, 2022
Professions and Applied Sciences
Amazing work!
Customer 452707, May 29th, 2022
Other
AWESOME
Customer 452813, June 21st, 2022
Social Work and Human Services
Excellent Work
Customer 452587, November 22nd, 2021
Other
great
Customer 452813, June 25th, 2022
Professions and Applied Sciences
Thank you!
Customer 452707, March 4th, 2022
Application Letters
Well written essay, will definitely use this service in the future.
Customer 452773, April 14th, 2022
Nursing
I appreciate all the hard work. Thank you!
Customer 452525, August 13th, 2021
11,595
Customer reviews in total
96%
Current satisfaction rate
3 pages
Average paper length
37%
Customers referred by a friend
OUR GIFT TO YOU
15% OFF your first order
Use a coupon FIRST15 and enjoy expert help with any task at the most affordable price.
Claim my 15% OFF Order in Chat