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
import java.util.Scanner; import java.util.Random; public class DiceRoll {    public static final int SIDES = 6;...
import java.util.Scanner; import java.util.Random; public class DiceRoll {    public static final int SIDES = 6;    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Enter the number of times a 6 sided die should be rolled ");        Scanner keyboard = new Scanner(System.in);        Random r = new Random();               int times = keyboard.nextInt();        boolean valid = false;        while(!valid) {           ...
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...
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;...
Determine how all of your classes are related, and create a complete UML class diagram representing...
Determine how all of your classes are related, and create a complete UML class diagram representing your class structure. Don't forget to include the appropriate relationships between the classes. GameDriver import java.util.Scanner; public class GameDriver { Scanner in = new Scanner(System.in); public static void main(String[] args) { Move move1 = new Move("Vine Whip", "Grass", 45, 1.0f); Move move2 = new Move("Tackle", "Normal", 50, 1.0f); Move move3 = new Move("Take Down", "Normal", 90, 0.85f); Move move4 = new Move("Razor Leaf", "Grass",...
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...
What's wrong with this code? #Java Why I am getting error in : int BusCompare =...
What's wrong with this code? #Java Why I am getting error in : int BusCompare = o1.numberOfBusinesses.compareTo(o2.numberOfBusinesses); public class TypeComparator implements Comparator<Type> { @Override public int compare(Type o1, Type o2) { // return o1.name.compareTo(o2.name); int NameCompare = o1.name.compareTo(o2.name); int BusCompare = o1.numberOfBusinesses.compareTo(o2.numberOfBusinesses); // 2-level comparison using if-else block if (NameCompare == 0) { return ((BusCompare == 0) ? NameCompare : BusCompare); } else { return NameCompare; } } } public class Type implements Comparable<Type> { int id; String name; int...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT