1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Firdavs [7]
4 years ago
5

Your program Assignment This game is meant for tow or more players. In the same, 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 pints closest to one, when all rounds have been played, sins.) 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. I will attach the books code that must be converted to import javax.swing.JOptionPane; Example: Round 1: James rolled a 4 Sally rolled a 2 James: 46 Sally: 48 OK
Computers and Technology
1 answer:
Anika [276]4 years ago
5 0

Answer:

The code is given below in Java with appropriate comments

Explanation:

//Simulation of first to one game

import java.util.Random;

public class DiceGame {

  // Test method for the Dice game

  public static void main(String[] args) {

      // Create objects for 2 players

      Player player1 = new Player("P1", 50);

      Player player2 = new Player("P2", 50);

      // iterate until the end of the game players roll dice

      // print points after each iteration meaning each throw

      int i = 0;

      while (true) {

          i++;

          player1.rollDice();

          System.out.println("After " + (i) + "th throw player1 points:"

                  + player1.getPoints());

          if (player1.getPoints() == 1) {

              System.out.println("Player 1 wins");

              break;

          }

          player2.rollDice();

          System.out.println("After " + (i) + "th throw player2 points:"

                  + player2.getPoints());

          if (player2.getPoints() == 1) {

              System.out.println("Player 2 wins");

              break;

          }

      }

  }// end of main

}// end of the class DiceGame

// Player class

class Player {

  // Properties of Player class

  private String name;

  private int points;

  // two argument constructor to store the state of the Player

  public Player(String name, int points) {

      super();

      this.name = name;

      this.points = points;

  }

  // getter and setter methods

  public String getName() {

      return name;

  }

  public void setName(String name) {

      this.name = name;

  }

  public int getPoints() {

      return points;

  }

  public void setPoints(int points) {

      this.points = points;

  }

  // update the points after each roll

  void rollDice() {

      int num = Die.rollDice();

      if (getPoints() - num < 1)

          setPoints(getPoints() + num);

      else

          setPoints(getPoints() - num);

  }

}// end of class Player

// Die that simulate the dice with side

class Die {

  static int rollDice() {

      return 1 + new Random().nextInt(6);

  }

You might be interested in
What should be the extension to execute files?
Ganezh [65]
The correct answer is D. All of the above. Each of these extensions are able to execute files depending on what type of information the file contains.
5 0
3 years ago
What are the different types of topology?​ in details
wlad13 [49]

Answer:

<h2> <u>NETWORK</u> <u>TOPOLOGY</u> .</h2>

This tefers to how nodes are connected to the network.

Types of topology.

  • Physical topology.
  • Logical topology.

In physical topology,nodes are connected physically using wires(cables).

Types of physical topology include:

  • Bus topology
  • Tree topology
  • Hybrid topology
  • Star topology
  • Ring topology.

Hope it helps you,any question so far...comment !!!

3 0
2 years ago
Read 2 more answers
How is cropping different from scaling?​
Keith_Richards [23]

Answer:

Scaling changes the size of the whole image by resampling it(duplicating the pixels). in cropping you only get a part of the original image/ remove the outer area of it .

Explanation:

8 0
3 years ago
What should you do when an error message pops up on the screen?
Shtirlitz [24]
The best thing to do when an error message appears when it is not supposed to, as in if you are blocked by an administrator and it appears then its supposed to, it is best to contact someone who can investigate whether or not something is happening to your computer. That could be a parent, if they are good with computers, or just tech support at a store, provided they also know computers. Most of the time your computer just makes a mistake so nothing to worry about, but make sure to have it checked just to be sure. 
7 0
3 years ago
Please
Andrew [12]

Answer:

C. 2^16

Explanation:

In Computer Networking, there are five (5) classes of IP addresses, these include;

- Class A

- Class B

- Class C

- Class D

- Class E

The various classes of IP address are represented by the value of their first octet. The first octet value of Class B is 128-191 with a subnet mask of 16.

Hence, from the IP address 149.130.x.y where x and y are 8-bit numbers. The x and y equals 16-bit numbers.

Thus, 2^16 devices can connect to the Wellesley network before we run out of IP addresses.

3 0
3 years ago
Other questions:
  • Given non-negative integers x and n, x taken to the nth power can be defined as: x to the 0th power is 1 x to the nth power can
    7·1 answer
  • I have been trying to work on this for a while now, and this is on excel
    11·1 answer
  • I have a question about a hotel tv:
    10·1 answer
  • A person you respect who offers you advice and assistance is known as a(n) _____.
    12·1 answer
  • This project is to mimic a meeting request system by checking the requesting party’s validity, and the number of people attendin
    15·1 answer
  • The Open Systems Interconnection (OSI) is a conceptual model whose purpose is to make networks more manageable. Its objectives i
    15·1 answer
  • "If a user on a laptop complains that they are unable to sign into Windows even though they are certain they are entering the co
    12·1 answer
  • _________________________ are the countable products resulting from a program, while ________________________ are the changes in
    9·1 answer
  • Susan is a network monitoring technician working on a firewall for her company’s network. In the process to determine an open po
    8·1 answer
  • What is e banking effects
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!