Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Die class and DiceCup class CSC object-Oriented Project help Can someone please explain how to do this in detail? I'm confused. Thanks! ILJUULL SUULJ PUJLLU01W00

Die class and DiceCup class CSC object-Oriented Project help

image text in transcribedimage text in transcribed

Can someone please explain how to do this in detail? I'm confused. Thanks!

ILJUULL SUULJ PUJLLU01W00 Part 1: A Dice and Dice Cup Class In this part, you will be creating 2 classes to represent (1) a random die and (2) a "dice cup" used to store and roll multiple dice. The Die Class Begin by creating a Die class in order to be able to create Die objects Each die object should store inside itself (1) the number of sides that it has and (2) the result of rolling the die. For example, if we were to call a die object's roll() method, it should "roll" the random die and set the result to a number between 1 and the number of sides of the die. You will want to explore the Math class in Java's API and you will need to review the resource on Moodle about Typecasting to properly generate integer values. Your Die class should have a constructor that takes one input: (1) the number of sides that the die objeet- has. Your constructor should initialize the result to be a random-number between 1 and the number of sides. Your Die class should also define a roll() method that, when called, simulates rolling" a truly random die (i.e., each side has equal probability of being the result) Your Die class should also define an accessor ("getter") method to return the number of sides that the die has Your Die class should also define an accessor ("getter") method to return the die's result (value) - note: this should not cause your die to be re-rolled, it should strictly return the die's current value The DiceCup Class Next, create a DiceCup class in order to be able to create a "dice cup" capable of storing multiple dice A dice cup object should store inside itself (1) the capacity (i.e., the maximum number of dice it can hold) and (2) an array that is capable of holding up to the maximum number of dice. You will want to review the resource on Moodle about Arrays. . Your DiceCup class should have a constructor that takes one input: (1) the capacity of the cup - Your DiceCup class should define an addDie() method that allows the user to provide a Die objeat as input that should be added to the DiceCup's array Your DiceCup class should define a removeDie() method that removes the most recently added die from the DiceCup's array. Your DiceCup class should define a rollAllDice() method that rolls" any dice that are in the DiceCup Your DiceCup class define a printDice() method that prints the dice's results to the screen in the form below. For example, if our DiceCup had three dice, then calling printDice() should display the followin Your DiceCup class should define a howMany() method that allows the user to determine how many dice in the cup have a particular value on their face. For example, if the dice in the cup were {4, 6, 9, 2, 6, 6, 3} and the user called howMany(6), then the method should return 3 since there are 3 dice in the cup with a result of 6. Your DiceCup class should define a mostCommonValue() method that allows the user to determine which die value was the most common value in the cup. For example, if the dice in the cup were [4, 19, 22, 4, 6, 10, 7, 4), then your method should return 4 since it is the most common value in the cup. If there is a tie for the "most common value", your method can simply return one of the tied values (do not worry about trying to return which values are tied unless you want to for fun). Your DiceCup class should define a numPairs() method that returns the number of pairs" of dice that are in the DiceCup. For example, if the dice in the cup were [4, 19, 12,4,3,6,9,6, 19), then the method should return 3 since there are 3 pairs of dice in the cup with the same value. Your DiceCup class should define a longestSequence() method that returns the length of the longest consecutive (i.e., in a row") sequence of dice values in the cup. For example, if the dice in the cup were [7, 4, 2, 8, 3, 5, 9, 1), then this method should return 5 because the longest sequence of consecutive dice values is [1, 2, 3, 4, 5] which has a length of 5. The only time that text should be printed to the screen is when I call your printDice() method of your DiceCup class. You will lose points if any other method of your Die or DiceCup method prints information to the screen

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

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

What are economic events?

Answered: 1 week ago

Question

4. How is culture a contested site?

Answered: 1 week ago