Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to build a Yahtzee game in Java. I have some classes/objects but am hung up on how to continue and I think

I am trying to build a Yahtzee game in Java. I have some classes/objects but am hung up on how to continue and I think what I currently have is a mess.

This is Part 1 requirements:

Create a stub Die class based on the UML specs in the following pages. Write a driver program for Die class according to UML specs and class description. Your program should be designed to thoroughly test each of the class methods. Now implement the Die class according to UML specs. Use your driver to help identify bugs in your code.

Description of Part 1:

The Die class represents a die used in board games that has numeric values from MIN_VALUE to MAX_VAULE on its sides. For our purposes we will assume that the die is fair, so that each face has equal probability of turning up. Variables faceValue: int An integer between MIN_VALUE and MAX_VALUE. This will represent the value showing on the die after it has been rolled. (Before the die is rolled, this value may be 0.) MAX_VALUE: int A class variable (i.e. static) that represents the maximum allowable value of any die. MIN_VALUE: int A class variable (i.e. static) that represents the minimum allowable value of any die. Functions: roll(): void Generate a random integer between MIN_VALUE and MAX_VALUE (inclusive), and assign that integer to faceValue. getValue(): int Return the current faceValue of this die object. setMin(int newMin): void A class function (i.e. static) that sets MIN_VALUE to newMin. Must ensure that newMin > 0 and newMin < MAX_VALUE. setMax(int newMax): void A class function (i.e. static) that sets MAX_VALUE to newMax. Must ensure that newMax > 0 and newMax > MIN_VALUE. getMin(): int A class function (i.e. static) that returns MIN_VALUE getMax(): int A class function (i.e. static) that returns MAX_VALUE

This is what I have for part 1 but feel it is too much or not correct:

public class Die { public static void main(String[] args) { } private int faceValue; private int Max_Value; private int Min_Value;

public Die() { this.faceValue=0; this.Max_Value=0; this.Min_Value=0; } public Die(int faceValue, int Max_Value, int Min_Value) { this.faceValue=0; this.Max_Value=6; this.Min_Value=1; } public Die(Die d) { this.faceValue=d.getFaceValue(); this.Max_Value=d.getMax_Value(); this.Min_Value=d.getMin_Value(); } public void roll() { /**Math.ceil * */ this.faceValue = (int)(Math.random() *6) +1; } public int getFaceValue() { return this.faceValue; }

public int getMax_Value() { return this.Max_Value; } public void setMax_Value(int max_Value) { this.Max_Value = max_Value; } public int getMin_Value() { return this.Min_Value; } public void setMin_Value(int min_Value) { this.Min_Value = min_Value; } public String toString() { return Integer.toString(faceValue); }

}

This is Part 2 requirements:

Create a stub YahtzeeDice class based on the UML specs in the following pages. Write a driver program for YahtzeeDice class according to UML specs and class description. Your program should be designed to thoroughly test each of the class methods. Now implement the Yahtzee class according to the UML specs. Use your driver to help identify bugs in your code

Description of Part 2:

Description The YahtzeeDice class represents a collection of some number of Die objects. Variables dice: Die[] An array of Die objects. The size of this array will be NUMBER_OF_DICE. This will represent the collection of dice cast during a Yahtzee turn. rollNumber: int An integer representing the number of times the dice have been rolled. NUMBER_OF_DICE: int. A class variable (i.e. static) that represents the number of dice that were allowed to use. This should correspond to the size of the array dice. MAX_ROLLS: int. A class variable (i.e. static) that represents the maximum number of times well let the player re-cast the dice. Functions: rollDice(Boolean rollers[]): void rollers [] is an array of boolean values of length NUMBER_OF_DICE. If rollers [i] is true, call the roll method of dice[i]. Increment rollNumber. Do not return a value. isYahtzee(): boolean Return True if all of the Die objects in dice have the same face value; return False otherwise. chanceScore(): int Return the chance score of the Die objects in dice. The chance score is the sum of all of the face values. getRollNumber(): int Return the number of times the dice have been rolled. setNumberDice(int n): void A class function (i.e. static). Sets NUMBER_OF_DICE to be n. Must ensure that n > 1. setMaxRolls(int n): void A class function (i.e. static). Sets MAX_ROLLS to be n. Must ensure that n > 1. getMaxRolls(): int A class function that returns MAX_ROLLS

This is what I have for part 2 but it is wrong and I don't know where to go or how to complete it:

import java.sql.Array;

public class YahtzeeDice extends Die{ protected Array dice; private int rollNumber; private int Number_of_Dice; private int Max_Rolls;

public static void main(String[] args) { // TODO Auto-generated method stub } } public static void rollDice(Boolean rollers[]) { }

public int getRollNumber() { return rollNumber; }

public void setRollNumber(int rollNumber) { this.rollNumber = rollNumber; }

public void setNumber_of_Dice(int number_of_Dice) { Number_of_Dice = number_of_Dice; }

public int getMax_Rolls() { return Max_Rolls; }

public void setMax_Rolls(int max_Rolls) { Max_Rolls = max_Rolls; } } I don't know how to continue from part 2 to complete part 3:

Part 3 Use your Die and YahtzeeDice classes to create a simple console-based Yahtzee game. o Before the game begins: Ask the user how many sides their dice have. (Assume that the MIN_VALUE is 1, and use the users input to set the MAX_VALUE.) Ask the user how many dice theyd like to play with. Ask the user how many times theyd like the user to be able to re-cast the dice. o Once the game has begun: Ask the user to roll the dice. Allow the user to re-roll the dice until they reach the maximum number of rolls. With each re-roll, ask the user which dice theyd like to keep and which ones theyd like to re-roll. After each turn, check to see whether the user has gotten a Yahtzee. After each turn, compute the users chance score. When the rolls have been exhausted, ask the user whether theyd like to play again.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2017 Skopje Macedonia September 18 22 2017 Proceedings Part 3 Lnai 10536

Authors: Yasemin Altun ,Kamalika Das ,Taneli Mielikainen ,Donato Malerba ,Jerzy Stefanowski ,Jesse Read ,Marinka Zitnik ,Michelangelo Ceci ,Saso Dzeroski

1st Edition

3319712721, 978-3319712727

More Books

Students also viewed these Databases questions