Question

#2 New Turn Rules A frustrating aspect of programming on a project with other programmers is the ...

#2 New Turn Rules

A frustrating aspect of programming on a project with other programmers is the fact that everyone solves problems in different ways. Just when you think you know which way things are headed, someone throws a snag in your design.

Objects needed:

  • Die
    • Attributes
      • Current value of the die
    • Actions
      • roll the die
  • DiceSet
    • Attributes
      • An array of six Die
      • The number of dice available to roll. When this number reaches 0, it is reset to 6.
      • The score of the current dice
    • Actions
      • roll the available dice
      • score the dice rolled and adjust the number of dice available to roll
  • Human
    • Attributes
      • Name
      • Accumulative score for the game
      • Score for the current round
    • Actions
      • play a turn
      • decide whether the player can continue or must continue. If he can continue, ask if he wants to roll again or not.

A human player continues his turn until:

  • His last roll contains no points. If this happens, the play receives no points for the current turn -- he has zilched.
  • If his total accumulated points is less than the meld limit, then he must continue rolling, even if the odds for receiving points are poor.
  • If his total accumulated points is greater than or equal to meld limit, then he has a choice of continuing to roll or stopping with his current score.
  • The meld limit for this assignment is 250

Scoring:

  • At the start of a turn, all six dice are rollable.
  • Dice that contribute to the score in a roll are set aside and are not rolled again
  • If all six dice are scored, then all six become rollable again.
  • As before, a 1 scores 100 points and a 5 scores 50 points. All other dice at this time score no points.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here are the first 3 classes - Die, DieSet and Human

==========================================================================

import java.util.Random;

public class Die {

    private int faceValue;
    private Random random = new Random();

    public Die() {
        faceValue = 0;
    }

    public void roll() {
        faceValue = random.nextInt(6) + 1;
    }

    public int getFaceValue() {
        return faceValue;
    }
}

==========================================================================

public class DiceSet {

    private Die[] sixDice;
    private int score;

    public DiceSet() {
        sixDice = new Die[6];
    }

    public void roll() {
        score = 0;
        for (Die die : sixDice) {
            die.roll();
            score += die.getFaceValue();
        }
    }

    public int getScore() {
        return score;
    }
}

==========================================================================

public class Human {

    private DiceSet diceSet;
    private int currentScore;
    private int totalScore;

    public Human() {
        diceSet = new DiceSet();
        currentScore = totalScore = 0;
    }

    private void roll() {
        diceSet.roll();
        currentScore = diceSet.getScore();
        totalScore += currentScore;
    }

    public int getCurrentScore() {
        return currentScore;
    }

    public int getTotalScore() {
        return totalScore;
    }

    public void play() {
        roll();
    }
}

==========================================================================

Add a comment
Know the answer?
Add Answer to:
#2 New Turn Rules A frustrating aspect of programming on a project with other programmers is the ...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Homework: This will be the first in a series of assignments to create a game...

    C++ Homework: This will be the first in a series of assignments to create a game called Zilch. In this assignment, you will create the basic structure of the program and demonstrate the ability to create programs with multiple files. It should serve as a refresher in the basics of C++ programming, especially in the handling of arrays. The initial assignments only establish a rough outline of the game. We will be adding the rules that make the game more...

  • The game of Pig is a simple two-player dice game in which the first player to...

    The game of Pig is a simple two-player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn, a player rolls a six-sided die: If the player rolls a 1, then the player gets no new points and it becomes the other player’s turn. If the player rolls 2 through 6, then he or she can either ROLL AGAIN or HOLD:      At this point, the sum of all rolls...

  • The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players...

    The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 (”pig”) is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player’s turn, the player is faced with two decisions: roll If the player rolls a 1: the player scores nothing and it becomes the...

  • WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a...

    WITHOUT FUNCTIONS. Could anyone help me solve this problem not using the function ? Thanks a lot. Pig Dice Game Pig is a simple two player dice game, played with one die. The first player to reach or surpass 50 is the winner. Each player takes a turn rolling the dice. They add to the pot with each roll, having to decide to roll again and increase the pot, or cash out. The risk being they could lose the amount...

  • For your final project you will incorporate all your knowledge of Java that you learned in this class by programming the game of PIG. The game of Pig is a very simple jeopardy dice game in which two p...

    For your final project you will incorporate all your knowledge of Java that you learned in this class by programming the game of PIG. The game of Pig is a very simple jeopardy dice game in which two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn,...

  • Requirements: 1. You are not allowed to use global variables. 2. Must declare the following two...

    Requirements: 1. You are not allowed to use global variables. 2. Must declare the following two constants public static final int POINTS = 30; public static final int FORFEIT_POINTS = 20; 3. You can implement your own solution but you are required to break down the problem into smaller pieces. 4. You must provide the output for two rounds of game minimum. 5. Since we are using the Random number generator your output will not be exactly like mine. However,...

  • Two player Dice game In C++ The game of ancient game of horse, not the basketball...

    Two player Dice game In C++ The game of ancient game of horse, not the basketball version, is a two player game in which the first player to reach a score of 100 wins. Players take alternating turns. On each player’s turn he/she rolls a six-sided dice. After each roll: a. If the player rolls a 3-6 then he/she can either Roll again or Hold. If the player holds then the player gets all of the points summed up during...

  • The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values...

    The Dice game of "Pig" can be played with the following rules. 1. Roll two six-sided dice. Add the face values together. 2. Choose whether to roll the dice again or pass the dice to your opponent. 3. If you pass, then you get to bank any points earned on your turn. Those points become permanent. If you roll again, then add your result to your previous score, but you run the risk of losing all points earned since your...

  • please write the following program in Java PIG is one of a family of games called...

    please write the following program in Java PIG is one of a family of games called jeopardy dice games, since a player's main decision after each roll is whether to jeopardize previous gains by trying for potentially even greater gains. In PIG, all players start with ZERO points, and each turn involves rolling a die to earn points. The first player to earn 100 points or more total shouts "PIG!" and wins the game. On their turn, a player does...

  • Hello, Could you please help me code this program in Java? It is important that all...

    Hello, Could you please help me code this program in Java? It is important that all rules are carefully followed. Using the PairOfDice class from PP 4.9, design and implement a class to play a game called Pig. In this game, the user competes against the computer. On each turn, the current player rolls a pair of dice and accumulates points. The goal is to reach 100 points before your opponent does. If, on any turn, the player rolls a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT