Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This assignment is mainly about association, but also covers constructors and overloading. You will define multiple classes that implement a simple best of 3 multi-round

This assignment is mainly about association, but also covers constructors and overloading. You will define multiple classes that implement a simple best of 3 multi-round dice game. All the objects will be related to one another through the relationship of association. Then you will create a simple textbased app to display the result of playing two games of 3 rounds each. The Objects A Die (die is the singular of dice) has an integer number of sides. It can roll itself, and it can report the side thats currently showing. A Player has a name, 3 dice, and a score that starts at 0. A player can take a turn, which involves rolling 3 dice and adding the two highest to its score. A Game consists of two players. A game is played by having each player take 3 turns, one after another. The person with the highest score at the end is winning the game (or if the scores are the same, its a tie). Code Structure The UML diagram below shows which classes you are to develop and how they relate to one another. Game Class By default, a Game uses 6-sided dice but you can override that using the second constructor. The Game constructor creates the two Player objects. The playTextGame method plays a multi-round game using the NUM_ROUNDS constant to determine how many rounds. This constant should be set to 3. Each round, it calls the takeTurn method for each Player, reports the score for that round for each Player, then prints each Player object to System.out. The toString method returns a string with the number of sides on the dice, each players name and score, and the name of the player who is currently winning (or state its a tie). Player By default, the players dice have 6 sides but you can override that using the second constructor. The Player constructor creates the three Dice objects. A player starts with 0 points. The takeTurn method rolls all 3 dice, adds up the two highest numbers for the turn score, adds the turn score to the players total score, and returns the turn score. The toString method returns a string containing the players name, their score, and their three dice. Die The roll method generates a random number between 1 and numSides and stores that as the number showing. The toString method prints the number currently showing and the number of sides. TextGame You also need a TextGame class (not shown above). It has a main method that creates 2 Game objects. You choose the player names for the games. One game should use default dice, the other uses dice you choose (20-sided, 10-sided, etc.). Print the number of rounds that will be played. Then for each game: Print the game object Call its playTextGame method Print the game object again When your program is tested, it will be run using the TextGame class you handed in, then again using another standard TextGame class to make sure your Game, Player, and Die classes conform to the interface shown in the UML diagram. The Output Heres an example of what the output of your program might look like. Yours might differ. Games are 3 Rounds Game Summary: 6-sided dice. Max has 0 points, Rosa has 0 points. It's a tie so far... Round 1. Max rolls 8 Rosa rolls 8 Player Max: score=8, dice={2/6,1/6,6/6} Player Rosa: score=8, dice={3/6,2/6,5/6} Round 2. Max rolls 7 Rosa rolls 6 PlayerMax: score=15, dice={3/6,1/6,4/6} PlayerRosa: score=14, dice={1/6,3/6,3/6} Round 3. Max rolls 12 Rosa rolls 6 PlayerMax: score=27, dice={6/6,4/6,6/6} PlayerRosa: score=20, dice={1/6,4/6,2/6} Game Summary: 6-sided dice. Max has 27 points, Rosa has 20 points. Max is Winning! Game Summary: 20-sided dice. Sam has 0 points, Anne has 0 points. It's a tie so far... Round 1. Sam rolls 18 Anne rolls 25 Player Sam: score=18, dice={4/20,3/20,14/20} Player Anne: score=25, dice={9/20,7/20,16/20} Round 2. Sam rolls 7 Anne rolls 26 Player Sam: score=25, dice={1/20,2/20,5/20} Player Anne: score=51, dice={11/20,15/20,9/20} Round 3. Sam rolls 28 Anne rolls 24 Player Sam: score=53, dice={15/20,13/20,8/20} Player Anne: score=75, dice={11/20,13/20,4/20} Game Summary: 20-sided dice. Sam has 53 points, Anne has 75 points. Anne is Winning!

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_2

Step: 3

blur-text-image_3

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

1. How has past European colonialism impacted todays Africans?

Answered: 1 week ago

Question

2. What type of team would you recommend?

Answered: 1 week ago