Question

In java create a dice game called sequences also known as straight shooter. Each player in...

In java create a dice game called sequences also known as straight shooter. Each player in turn rolls 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 1's cancels out player's score and they mst start from 0. 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 : cancel players 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). Create a die class, game class and 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 winner's name and ask the user is he/she wants to play again. keep running total of games won and lost by each of the two players. (Here is something similar. it needs to be fixed) Die.java import java.util.Random; //Die class public class Die { private int faceUp; private final int NumberOfSides=6; //constructor public Die() { faceUp = 1; } //method to roll() public void roll() { faceUp = (int)(Math.random() * NumberOfSides) +1; } //Method to compare public void CompareTo(int value) { faceUp=value; } //Method to getFace() public int getFace() { return faceUp; } //method equals public boolean equals(int die) { die=faceUp; return true; } //Method to string public String toString() { String result = "You rolled a " + faceUp; return result; } } Sequence.java //Sequence class public class Sequence { //Data members private Die dies1, dies2; private int FirstVal, SecondVal, Tot; //constructor public Sequence () { dies1 = new Die(); dies2 = new Die(); FirstVal = 1; SecondVal = 1; Tot = FirstVal + SecondVal; } //Method to roll() public void roll () { dies1.roll(); dies2.roll(); } //Method to SumOfDice() public int SumOfDice () { Tot = firstDie() + SecondDie(); return Tot; } //Method to firstDie() public int firstDie () { return FirstVal; } //Method to SecondDie() public int SecondDie () { return SecondVal; } //Method to set FirstDieSet() public void FirstDieSet (int value) { dies1.CompareTo(value); } //Method to set SecondDieSet() public void SecondDieSet(int value) { dies2.CompareTo(value); } //Method to string() public String toString() { String result = "You rolled a " + Tot; return result; } } DieTester.java: import java.util.*; //tester class public class DieTester { //Main program public static void main(String[] args) { //Instance for class Sequence seq=new Sequence(); //Assign values int totalTurns = 0; int player2Tot = 0; int player1Tot = 0; int CompleteTurn = 1; int Wins = 100; //Scanner object Scanner inp = new Scanner( System.in); String Result; //do loop do{ if (player1Tot <= Wins && player2Tot <= Wins) { System.out.println("Your turn."); //do loop do { System.out.println("Enter 'y' or 'n' for turn."); Result = inp.next(); //Equals ignore case check if (Result.equalsIgnoreCase("y") && player1Tot <= Wins && player2Tot <= Wins) { //Calls the methods seq.roll(); seq.firstDie(); seq.SecondDie(); seq.toString(); System.out.println(seq);                        //Checks the sequence data if (seq.firstDie() == CompleteTurn || seq.SecondDie() == CompleteTurn){ System.out.println("You are Rolled a 1. Your turn is over."); System.out.println("'Enter 'done' for Player 2."); Result = inp.next(); } else { //Computes the results totalTurns = totalTurns + seq.SumOfDice(); player1Tot = player1Tot + seq.SumOfDice(); System.out.println("Turn Total of player1: " + totalTurns); System.out.println("Grand Total of player2: " + player1Tot); } } } //Checks the ignore case while (Result.equalsIgnoreCase("y") && player1Tot <= Wins && player2Tot <= Wins); totalTurns = 0; System.out.println(); System.out.println("Player1 Grand Total: " + player1Tot); System.out.println("Player2 GrandTotal: " + player2Tot); System.out.println(); //Assigns value int CturnEnd = 20; CompleteTurn = 1; int CompareResults = 1; //do while do { if (totalTurns <= CturnEnd && CompareResults == 1 && player1Tot <= Wins && player2Tot <= Wins) { //calls the methods seq.roll(); seq.firstDie(); seq.SecondDie(); seq.toString(); System.out.println(seq); //Compute the results if (seq.firstDie() == CompleteTurn || seq.SecondDie() == CompleteTurn) { System.out.println("Player2 rolled a 1. Their turn is over."); CompareResults = 0; } else { //Calculation totalTurns = totalTurns + seq.SumOfDice(); player2Tot = player2Tot + seq.SumOfDice(); System.out.println("Turn Total of Player2 is: " + totalTurns); System.out.println("GrandTotal of Player2 is: " + player2Tot); } } } while (totalTurns <= CturnEnd && CompareResults == 1 && player1Tot <= Wins && player2Tot <= Wins); totalTurns = 0; //Checks the player total if (player1Tot <= Wins || player2Tot <= Wins) { System.out.println(); System.out.println("Player2 GrandTotal is: " + player2Tot); System.out.println("Player1 GrandTotal is: " + player1Tot); System.out.println(); } else { System.out.println(); System.out.println(); } } } //winning result while(player1Tot <= Wins && player2Tot <= Wins); //decision result if (player1Tot >= Wins) System.out.println("You win!"); else System.out.println("You lose ): "); } }

Homework Answers

Answer #1
 public class PairOfDice {
     
        private int die1;   // Number showing on the first die.
        private int die2;   // Number showing on the second die.
        
        public PairOfDice() {
                // Constructor.  Rolls the dice, so that they initially
                // show some random values.
            roll();  // Call the roll() method to roll the dice.
        }
        
        public void roll() {
                // Roll the dice by setting each of the dice to be
                // a random number between 1 and 6.
            die1 = (int)(Math.random()*6) + 1;
            die2 = (int)(Math.random()*6) + 1;
        }
                 
        public int getDie1() {
              // Return the number showing on the first die.
           return die1;
        }
        
        public int getDie2() {
              // Return the number showing on the second die.
           return die2;
        }
        
        public int getTotal() {
              // Return the total showing on the two dice.
           return die1 + die2;
        }
        
     }  // end class PairOfDice
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
THIS IS FOR JAVA I have to write a method for a game of Hangman. The...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The word the user is trying to guess is made up of hashtags like so " ###### " If the user guesses a letter correctly then that letter is revealed on the hashtags like so "##e##e##" If the user guesses incorrectly then it increments an int variable named count " ++count; " String guessWord(String guess,String word, String pound) In this method, you compare the character(letter)...
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
Java Language Add a method (convertToRing ()) that converts the list to a circular. This is,...
Java Language Add a method (convertToRing ()) that converts the list to a circular. This is, which makes the last node instead of pointing to null point to the first. Code: class Node { int value; Node nextNode; Node(int v, Node n) { value = v; nextNode = n; } Node (int v) { this(v,null); } } class LinkedList { Node head; //head = null; LinkedList() { } int length() { Node tempPtr; int result = 0; tempPtr = head;...
Java Language Add a method (convertToRing ()) that converts the list to a circular. This is,...
Java Language Add a method (convertToRing ()) that converts the list to a circular. This is, which makes the last node instead of pointing to null point to the first. Code: class Node { int value; Node nextNode; Node(int v, Node n) { value = v; nextNode = n; } Node (int v) { this(v,null); } } class LinkedList { Node head; //head = null; LinkedList() { } int length() { Node tempPtr; int result = 0; tempPtr = head;...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the...
JAVA public class Purchase { private String name; private int groupCount; //Part of price, like the 2 in 2 for $1.99. private double groupPrice; //Part of price, like the $1.99 in 2 for $1.99. private int numberBought; //Total number being purchased. public Purchase () { name = "no name"; groupCount = 0; groupPrice = 0; numberBought = 0; } public Purchase (String name, int groupCount, double groupPrice, int numberBought) { this.name = name; this.groupCount = groupCount; this.groupPrice = groupPrice; this.numberBought...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent...
Java: ModifyStudentList.javato use anArrayListinstead of an array In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and should add the given Student to the StudentList. The removeStudent method should have one parameter of type String. The String is the email of the student to be removed from the StudentList. In Assign5Test.java do the following: Create a new StudentList containing 3 students. Print the info of all the Students in the StudentList using...
IN JAVA Methods*: Calorie estimator Write a method ActivityCalories that takes a string indicating an activity...
IN JAVA Methods*: Calorie estimator Write a method ActivityCalories that takes a string indicating an activity (sit, walk, jog, bike, swim) and duration in minutes (integer), and returns the estimated calories expended (double). Calories per minute for a 150 lb person (source): sit: 1.4 walk: 5.4 run: 13.0 bike: 6.8 swim: 8.7 If the input is sit 2, the output is 2.8 Hints: Use an if-else statement to determine the calories per minute for the given activity. Return the calories...
Please explain code 1 and code 2 for each lines code 1 public class MyQueue {...
Please explain code 1 and code 2 for each lines code 1 public class MyQueue {    public static final int DEFAULT_SIZE = 10;    private Object data[];    private int index; code 2 package test; import java.util.*; /* Class Node */ class Node { protected Object data; protected Node link; /* Constructor */ public Node() { link = null; data = 0; } /* Constructor */ public Node(Object d,Node n) { data = d; link = n; } /*...
question : Take the recursive Java program Levenshtein.java and convert it to the equivalent C program....
question : Take the recursive Java program Levenshtein.java and convert it to the equivalent C program. Tip: You have explicit permission to copy/paste the main method for this question, replacing instances of System.out.println with printf, where appropriate. You can get the assert function from assert.h. Try running the Java program on the CS macOS machines. You can compile and run the program following the instructions discussed in class. Assertions are disabled by default. You can enable assertions by running java...
(JAVA) Why is my toString method not printing out the last node? It will not print...
(JAVA) Why is my toString method not printing out the last node? It will not print out "A" which is for Alice. Everything else is working just fine except for this. package driver; import exception.StackException; import stack.*; public class StackDriver { public static void main(String[] args) throws Exception { StackInterface<Painting> painting = new LinkedStack <Painting>(); try { System.out.println("Peeking at top of player stack.\n" + painting.peek()); }catch (StackException e) { System.out.println(e); System.out.println("Let's double check if it's empty: " + painting.isEmpty()); }...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT