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...
Please solve this problem in java. import java.util.Arrays; public class PriorityQueue { /* This class is...
Please solve this problem in java. import java.util.Arrays; public class PriorityQueue { /* This class is finished for you. */ private static class Customer implements Comparable { private double donation; public Customer(double donation) { this.donation = donation; } public double getDonation() { return donation; } public void donate(double amount) { donation += amount; } public int compareTo(Customer other) { double diff = donation - other.donation; if (diff < 0) { return -1; } else if (diff > 0) { return...
Complete the // TODO sections in the EasyRental class. Create a method that implements an iterative...
Complete the // TODO sections in the EasyRental class. Create a method that implements an iterative sort that sorts the vehicle rentals by color in ascending order (smallest to largest) Create a method to binary search for a vehicle based on a color, that should return the index where the vehicle was found or -1 You are comparing Strings in an object not integers. Ex. If the input is: brown red white blue black -1 the output is: Enter the...
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...
One of the most popular games of chance is a dice game known as “craps”, played...
One of the most popular games of chance is a dice game known as “craps”, played in casinos around the world. Here are the rules of the game: A player rolls two six-sided die, which means he can roll a 1, 2, 3, 4, 5 or 6 on either die. After the dice come to rest they are added together and their sum determines the outcome. If the sum is 7 or 11 on the first roll, the player wins....
Write a Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT