home / study / engineering / computer science / questions and answers / Create A
ID: 3806812 • Letter: H
Question
home / study / engineering / computer science / questions and answers / Create A Class Called Die Which Represents An N-faced ... Your question has expired and been refunded. We were unable to find a Chegg Expert to answer your question. Question: Create a class called Die which represents an n-fa... Bookmark Create a class called Die which represents an n-faced die that is used in game playing. a) The class has two fields, the number of sides the die has and the value of the side that is facing up (the face). b) Write a constructor which takes in an int as a parameter representing the number of sides the die has and then rolls the die to set the initial face value. This roll uses the Random class to determine the value of the face. Values on the die must be at least 1 and the upper limit is the number of faces. This means a standard six-faced die can have face values ranging from 1 to 6. Use the Java random number generator to do this. (Random) c) Write a compareTo( ) method to determine the ordering of two Die objects. This comparison is based solely on the value of the face field. d) Write an equals( ) method to determine if two Die objects should be considered equal based on both the number of sides AND the current face value. e) Write a copy constructor. f) Write a roll( ) method using the Random class which changes the value of the face field. g) Write a getFace( ) method. h) Write a toString( ) method that returns a text value of both the number of sides and the value of face. Use the BlueJ debugger to test each of the methods of the Die class before going on step 2. Step 2: Write a class named Sequences that has the methods needed to play the following game. Some fields to consider are an array of references to Die, an array of player’s names, an array of player’s scores… (you will use multiple arrays in the Sequences class). Write a Driver class that creates an instance of the Sequences class. The Driver will: control the number of players, read the player’s names from keyboard input (send to Sequences constructor to create the arrays) , keep track of many games are played, print the result of the roll for each turn, display the points for each roll and the total score, display who wins each individual game and the tally of each player’s wins. Sequences is also known as Straight Shooter. This game is played with six dice. To Play: 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 sequence counts. However a throw that contains three 1s cancels out a player's score and they must start from zero again. A total of each player’s score is kept and the first player to reach 100 points, wins the game. Scoring for a roll: 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
Explanation / Answer
The Die class that rolls a dice of sides
* The class have methods that returns the number of
* sides and value of dice*
/ //Die.h
#ifndef DIE_H
#define DIE_H
#include<stdlib.h>
#include<time.h> //instance variables of dice class class
using namespace std;
int main()
{
//seed the random number generator
//Note: this must be done before creating any Die class objects
srand(5);
//Create a Die class object and display the side that is currently up
Die die1;
cout << "The current side is " << die1.getValue();
//Roll the die 10 times to test the roll and getValue methods
for( int cnt = 1; cnt <= 10; cnt++ )
{
die1.roll();
cout << endl << endl << "Roll " << cnt << ":" << endl
<< "You rolled a " << die1.getValue() << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.