Question: In Java Each player in turn rolls the six dice and scores points for any sequence of consecutive numbers thrown beginning with 1. In the

In Java

Each player in turn rolls the six dice and scores points for any sequence of consecutive numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts.

However, a throw that contains three 1s cancels out a player's score and they must start from zero again.

A total of scores is kept and the first player to reach 100 points, wins the game.

1: 5 points

1, 2: 10 points

1, 2, 3: 15 points

1, 2, 3, 4: 20 points

1, 2, 3, 4, 5: 25 points

1, 2, 3, 4, 5, 6: 35 points

1, 1, 1: Cancels player's total score

nb: this is a non-interactive game when played on computer.

You will need two arrays of Die references, one for each player (human and computer). Use the Die class provided. Create an object-oriented design. Die class, Game class, Driver class

After each roll, print the faces of the dice and display the points for that roll along with the total accumulated points.

Once a game is won by a player, print the winners name and then ask the user if he/she wants to play again. Keep a running total of games won and lost by each of the two players (human and computer)

import java.util.*;

/**

* Information and methods for a game die (dice).

*

* @author Lorrie Lehmann

* @version v1

*/

public class Die

{

private int numberOfSides;

private int face;

private Random numberGenerator;//declare a reference

//variable for a Random

//object

public Die( )

{

numberOfSides = 6;

numberGenerator = new Random( );

roll( );

}

public Die( int inNumberOfSides)

{

numberOfSides = inNumberOfSides;

numberGenerator = new Random( );

roll( );

}

public void roll( )

{

face = numberGenerator.nextInt(numberOfSides) + 1;

}

public String toString( )

{

String result;

switch(face)

{

case 1: result = " _______ " +

"| | "+

"| * | "+

"| | "+

"'-------'";

break;

case 2: result = " _______ " +

"| *

| "+

"|

| "+

"|

* | "+

"'---

----'";

break;

case 3: result = " _______ " +

"| * | "+

"| * | "+

"| * | "+

"'-------'";

break;

case 4: result = " _______ " +

"| * * | "+

"| | "+

"| * * | "+

"'-------'";

break;

case 5: result = " _______ " +

"| * * | "+

"| * | "+

"| * * | "+

"'-------'";

break;

case 6: result = " _______ " +

"| * * | "+

"| * * | "+

"| * * | "+

"'-------'";

break;

default: result = "face is " + face;

}

return result;

}

public int getFace( )

{

return face;

}

public boolean equals(Die inDie)

{

return (face == inDie.face) && (numberOfSides ==

inDie.numberOfSides);

}

public int compareTo(Die inDie)

{

int answer;

if(face > inDie.face)

{

answer = 1;

}

else

{

if(face < inDie.face)

{

answer = -1;

}

else

{

answer = 0;

}

}

return answer;

}

}

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!