CSE110 Module7-Die Solved

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

Rate this product

Your client is developing a new Java class library to support group games. As lead developer, you have been tasked to design and implement one of the most fundamental classes in this library: Die (singular of Dice). Typically, the Dice we are familiar with is a cube with the values 1 through 6 on different faces. When rolled, the Die lands randomly showing one of the faces up, i.e. its “value”. Your client wants a more general Die that can represent a shape with any number of sides (> 1). Further, a Die can be “frozen” which will prevent its value from changing, even if someone tries to set its value or roll it.

In addition to writing the Class Die, you will need to write a test driver program to prove that the Die Class operates correctly. See the Required Test cases below, and the sample output.

2. Class Definition

Constructors (all public)

Die(int numSides): Creates a new, unfrozen Die with the given number of sides and initial value of 1. Ensure that the number of sides > 1. If not, print a message and assume 6 sides.

Die(): Creates a new Die with 6 sides by using the constructor above.

Accessors/Mutators public void setValue(int v): Set the value of the Die, if the status is not frozen. If the Die is frozen, ignore this request, without a message. Ensure that the value is compatible with the number of sides (0 < v <= numSides). If not, print a message and set the value to 1.

public int getValue(): Return the value of the Die.

Functions public void roll(): “Roll the Die” and set the value to the resulting value. If the Die is frozen, ignore this request, without a message. The resulting value should be between 1 and number of Sides, inclusive.

public void print(): Print a simple graphic for the Die: “[n:x]”, where n is the value, x is the number of sides.

public void draw(): If the number of sides <= 6, print a more realistic graphic for the Die. If the number of sides > 6, default to print(). The example for 5 is shown below:

…….

.     .

. * * .

.  *  .

. * * .

.     .

…….

public void freeze(): Set the status of the die so that it will not change value (Set setValue and roll).

public void unfreeze(): Set the status of the die so that it is allowed to change value (See setValue and roll).

3. Notes

  • I would suggest two classes: Die, and DieDriver (required). DieDriver will test Die by implementing the tests required below in “Required Test Cases”.
  • Use plenty of print statements in your output so the grader can understand the test you are running.
  • The Test Cases marked with an asterisk (*) should produce an error and keep going.
  • Turn in only your source files.
  • Because this program includes the verification built in, your verification table should match the tests and identify the expected output for each.
  1. Required Main Class

DieDriver

  1. Required Input

None

6. Required Test Cases

  1. Test the creation of Dice. Create and print each (d1, d2, d3) of the following Dice:
    1. d1: Create a default Die, print it
    2. d2: Create a die with 4 side, print it
    3. d3: Create a die with 10 sides, print it
  2. Test setting the value of Dice. Set the value and print the following Dice:
    1. d1: set to 3, print it
    2. *d2: set to 5, print it
    3. *d3: set to 0, print it
  3. Test freezing a Die. Set the value and print the following Dice:
    1. d1: freeze it, set the value to 5, print it
    2. d1: unfreeze it, set the value to 5, print it
  4. Test drawing a Die. Draw the following Dice:
    1. d1: Draw it
    2. d2: Draw it
    3. d3: Draw it
  5. Test rolling a Die.
    1. d1: Roll and print it 10 times.
    2. d2: Roll and print it 3 times.
    3. d3: Roll and print it 10 times.

7. Required Output

Your output should look something like the following example. It should include your name and a well-documented set of tests, as required above.

Note that your numbers rolled will likely be different, since this is based on random numbers.

 

Die Driver – E. Eckert

 

  1. Creation of Die

 

  1. [1:6]
  2. [1:4]
  3. [1:10]

 

  1. Setting Value of Die

 

*** Attempted to set value to 5, assumed 1. *** Attempted to set value to 0, assumed 1.

  1. [3:6]
  2. [1:4]
  3. [1:10]

 

  1. Freezing a Die

 

  1. [3:6]
  2. [5:6]

 

  1. Drawing a Die
    1. …….

.     .

. * * .

.  *  .

. * * .

.     .

…….

 

  1. …….

.     .

.     .

.  *  .

.     .

.     .

…….

 

  1. [1:10]

 

  1. Rolling a Die
    1. [6:6] [5:6] [5:6] [6:6] [2:6] [2:6] [5:6] [3:6] [2:6] [2:6]
    2. [4:4] [1:4] [3:4]
    3. [9:10] [7:10] [3:10] [6:10] [10:10] [6:10] [5:10] [2:10] [5:10] [2:10]

 

  • Mod-8-racofk.zip