I need help with creating a Java program described below:   A Game of Twenty-One:   Write a program that lets the user play against the computer in a variation of the popular blackjack card game. In this variation of the game, two six-sided dice are used instead of cards. The dice are rolled, and the player tries to beat the computer’s hidden total without going over 21.   Here are some suggestions for the game’s design: Each round of the game is performed as an iteration of a loop that repeats as long as the player agrees to roll the dice, and the player’s total does not exceed 21.  At the beginning of each round, the program will ask the user whether or not he or she wants to roll the dice to accumulate points. During each round, the program simulates the rolling of two six-sided dice. It rolls the dice first for the computer, and then it asks the user whether he or she wants to roll. Create a Die class to use with this application. The loop keeps a running total of both the computer and the user’s points. The computer’s total should remain hidden until the loop has finished. After the loop has finished, the computer’s total is revealed, and the player with the most points, without going over 21, wins.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need help with creating a Java program described below:

 

A Game of Twenty-One:

 

Write a program that lets the user play against the computer in a variation of the popular blackjack card game. In this variation of the game, two six-sided dice are used instead of cards. The dice are rolled, and the player tries to beat the computer’s hidden total without going over 21.

 

Here are some suggestions for the game’s design:

Each round of the game is performed as an iteration of a loop that repeats as long as the player agrees to roll the dice, and the player’s total does not exceed 21. 

At the beginning of each round, the program will ask the user whether or not he or she wants to roll the dice to accumulate points.

During each round, the program simulates the rolling of two six-sided dice. It rolls the dice first for the computer, and then it asks the user whether he or she wants to roll. Create a Die class to use with this application.

The loop keeps a running total of both the computer and the user’s points.

The computer’s total should remain hidden until the loop has finished.

After the loop has finished, the computer’s total is revealed, and the player with the most points, without going over 21, wins.

Expert Solution
Step 1: Providing the algorithm

1. Create a Die class to simulate rolling a six-sided die:
   - Define a Die class with a method roll() that returns a random number between 1 and 6.

2. Initialize variables for userTotal and computerTotal to keep track of their points.
   - Set continueGame to true to start the game loop.

3. Display a welcome message and game rules.

4. While continueGame is true and userTotal is less than or equal to 21:
   a. Roll two dice for the computer and calculate the computer's total.
   b. Display the computer's first roll, second roll, and total.
   c. Ask the user if they want to roll the dice:
      - If the user enters "yes":
        - Roll two dice for the user and calculate the user's turn total.
        - Display the user's first roll, second roll, and total.
        - Add the user's turn total to userTotal.
      - If the user enters "no":
        - Set continueGame to false to exit the loop.

5. Display the computer's total and the user's total.

6. Determine the winner:
   - If userTotal is less than or equal to 21 and (computerTotal is over 21 or userTotal is greater than computerTotal):
     - Display "Congratulations! You win!"
   - Else:
     - Display "Sorry, you lose. Better luck next time!"

7. End the game.


steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education