Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This project has 5 related parts. Each part will be graded please do not skip any parts. Each part asks you to create a class

This project has 5 related parts. Each part will be graded please do not skip any parts. Each part asks you to create a class by a specific name. Each class should have a main method. You are also encouraged (but not required) to write helper methods for each class which help the main method by breaking the problem into smaller pieces, as described in Chapter 6 which we will be discussing in class. Please create the 5 classes in the same BlueJ project.

Please do not call any methods in the Java class library specifically intended for sorting.

2. Write a class called GenerateDigits. The program should prompt the user to enter the number of digits to generate, or 0 to exit the program. The program should randomly generate the specified number of digits. After each digit is randomly generated, the program should display the count of the digits generated and the new random digit. Next, the program should construct a string consisting of the digits generated so far in non-decreasing order separated by spaces, and then output the string.

Be sure to test your program thoroughly.

Here is an example run of the program.

Please enter the number of digits to generate (or 0 to exit): 4 Count: 1. Random digit: 3. Digits so far in non-decreasing order: 3. Count: 2. Random digit: 1. Digits so far in non-decreasing order: 1 3. Count: 3. Random digit: 6. Digits so far in non-decreasing order: 1 3 6. Count: 4. Random digit: 3. Digits so far in non-decreasing order: 1 3 3 6. Please enter the number of digits to generate (or 0 to exit): 2 Count: 1. Random digit: 9. Digits so far in non-decreasing order: 9. Count: 2. Random digit: 5. Digits so far in non-decreasing order: 5 9. Please enter the number of digits to generate (or 0 to exit): 0 Have a nice day!

3. Write a class called InputDigits. The program should prompt the user to enter a string consisting of zero or more digits in any order with duplicates allowed and separated by spaces be sure to read this in as a single string. The program should construct a string with the digits in non-decreasing order separated by spaces. Finally the program should output the constructed string.

Be sure to test your program thoroughly.

Here is an example run of the program.

Please enter zero or more digits (or q to quit): 4 2 7 1 4 6 Here are the digits in non-decreasing order: 1 2 4 4 6 7 Please enter zero or more digits (or q to quit): Here are the digits in non-decreasing order: Please enter zero or more digits (or q to quit): q Have a nice day!

4. Write a class called InputOrGenerateDiceRolls. The program should ask the user whether the user prefers 1) to roll his/her own dice, 2) use computer-generated dice rolls, or 3) quit the program. If the user prefers to roll his/her own dice, the program should prompt the user to enter 5 digits in the range from 1-6 separated by spaces in any order with duplicates allowed. However, if the user prefers to use computer-generated dice rolls, generate 5 random digits in the range from 1-6 with duplicates allowed. Next, regardless of the users preference, display the 5 digits (representing 5 dice rolls) in non-decreasing order.

Be sure to test your program thoroughly.

Here is an example run of the program.

Please enter 1) to roll your own dice, 2) to let the computer roll the dice, or 3) to quit: 1 Please enter the five dice rolls: 4 2 6 1 1 The five rolls in non-decreasing order are: 1 1 2 4 6

Please enter 1) to roll your own dice, 2) to let the computer roll the dice, or 3) to quit: 2 The five rolls in non-decreasing order are: 2 4 4 5 5

Please enter 1) to roll your own dice, 2) to let the computer roll the dice, or 3) to quit: 3 Have a nice day!

5. Write a class called OneRoundOneRollYahtzee. The program should behave the same as the InputOrGenerateDiceRolls program with the following additional feature. After each set of five dice rolls has been displayed in non-decreasing order, the set of five dice rolls will be scored according to the rules of the dice game Yahtzee. Before the score for the roll can be determined, the user must be prompted for a category to be used for scoring the dice roll. The categories are listed on the next two pages which come from: https://en.wikipedia.org/wiki/Yahtzee

Note that the first six categories (collectively called the upper section) and category 13 (called Chance) can be chosen for any set of five dice rolls. However, categories 7-12 are only legal for certain dice rolls. If the user chooses a legal category for the dice roll, your program should compute the score as specified in the Scores column of the tables. However, if the user chooses an illegal category for the dice roll, your program should notify the user that his/her choice is illegal and allow him/her to select again.

Note that we are not simulating the full game of Yahtzee. We are only simulating one round of the game and the five dice are only being rolled once during this round. If the user chooses to play again he/she will be starting a new one-round game with all of the scoring categories available in the sense that they are un-used.

Please enter 1) to roll your own dice, 2) to let the computer roll the dice, or 3) to quit: 1 Please enter the five dice rolls: 4 2 6 1 1 The five rolls in non-decreasing order are: 1 1 2 4 6 You may select from the following scoring categories: Upper Section: 1. Aces 2. Twos 3. Threes 4. Fours 5. Fives 6. Sixes

Lower Section: 7. Three Of A Kind 8. Four Of A Kind 9. Full House 10. Small Straight 11. Large Straight 12. Yahtzee 13. Chance Please enter the number corresponding to your chosen category: 12 The Yahtzee category is not legal for this roll: 1 1 2 4 6. Please enter the number corresponding to your chosen category: 13 Your score for the Chance category is: 14.

Please enter 1) to roll your own dice, 2) to let the computer roll the dice, or 3) to quit: 3 Have a nice day!

image text in transcribed

Refere Review Upper section 1. Aceia Any combination The Rum of dicH with the number 1 3. Threes Any nomhiration The sum of dicR with the number 3 Project 1 [compatibility Model Lower section 7. Thr of A Kind At th 3, Chance ion the Ame dice scares 17 al cores 13

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

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions

Question

1. Who will you assemble on the team?

Answered: 1 week ago

Question

Did the team members feel that their work mattered

Answered: 1 week ago