Question: JAVA .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
JAVA .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 players names, an array of players 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 players 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 players 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 players 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
