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]
3 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]3 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
The marketplace is the essence of which of the following?
olchik [2.2K]

Answer:

Market place is the essence of "Buyers and Sellers" of the products that are available in the market.

Explanation:

Consumers/buyers are the persons that need something, but they cannot prepare it by themselves, and there are some people who produce some products or goods and want to sell the to earn some money.

To facilitate these both two, Market place is the place where people can buy or sell their products.

8 0
3 years ago
In the table below identify the data type that would be most suitable for the second field
marishachu [46]

Answer:

C.

Explanation:

The second field is Age. Age is expressed as a number so will most likely be stored in a number data type.

6 0
3 years ago
HELP ASAP, AND YES I KNOW, WRONG CATEGORY. SORRY!
netineya [11]

Answer:

ensemble I think I'm pretty sure

4 0
3 years ago
Read 2 more answers
What should you include in a persuasive speech
Vlad [161]

Answer:

Come up with a controversial topic, one that make your listeners think

Research the topic thoroughly that you have chosen

Understand the perspective of your audience. Keep your goal in mind. You are trying to persuade the audience to do or believe something .

7 0
3 years ago
You are an interior decorator, confronted with a dark living room. To lighten the room up, you have n candles and want to build
user100 [1]

Answer:

a)

Algorithm to find a solution of min. cost

Function:cost(Graph G,Graph G1);

GC --> empty graph

for i in edges E:

if E(i,j) in G:

c(i,j)=c(i,j)

else if E(i,j) in G1:

c(i,j)=-c(i,j)

Function:Mincost(Graph G):

GC=Cost(G,G1)

while(negativecycle(GC)):

Update residal graph(G1)

GC=Cost(G,G1)

mincost=sum of Cij*F(i,j)

return mincost;

Explanation:

a)

1) Start the program

2) Read the no. of edges and vertices and also read the cost of the two nodes.

3) Find the min cost by travelling to the destination i.e.. finding all possible min. cost values.

4) Compare the all possible min.cost values

5) And display the least min. cost

6) Stop the program

b)

<u>Correctness of algorithm</u>

1)Here in these algorithm we are calculating all the possible cases.

2)These algorithm also supports the negative cost.

3)These algorithm occupies more space.

4)Takes less time

5)so,these algorithm provides the cost efficient solution very effectively.

c)

<u>Run Time Analysis</u>

1) While reading the values during the run time the program execution will stop until user provides the values.

2) Based on the User input Output vary.

3) Time consumption and space consumption is depends on the no. of inputs the user is given.

6 0
3 years ago
Other questions:
  • SOMEONE PLEASE HELP ASAP!!
    14·2 answers
  • Differentiate between third and fourth generation of computer​
    6·1 answer
  • Karen has opened a new business and is using Google Display Ads to build awareness of her new products. How does Google Display
    6·1 answer
  • you just bought a new hard drive for your computer you plan to use this as a second hard drive to store all your you made files
    6·1 answer
  • Which encryption standard goes with the WPA2 protocol?<br> AES<br> DES<br> TKIP<br> WPS
    10·1 answer
  • The series of events that make up a story is called
    6·2 answers
  • Write a method called printRange that accepts two integers as arguments and prints the sequence of numbers between the two argum
    6·1 answer
  • Perform the following conversions from decimal to binary, octal and hexadecimal systems. a) 1710 b) 132110C) 36010d).7510e).3906
    8·1 answer
  • Is it true or false and incomplete doing can be saved in Paint​
    15·1 answer
  • How does your ability to correctly count change affect the impression the customer has of you?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!