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)...
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...
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] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT