Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Additional requirements: -Solution must be object-oriented design remonstrated with a driver. -Welcome the user with a message that you read from a file called input.txt.
Additional requirements:
-Solution must be object-oriented design remonstrated with a driver.
-Welcome the user with a message that you read from a file called "input.txt".
-Write the results of the game to the terminal and also to the output file called, "output.txt" and remind the user to look at that file if he/she wants to.
Pseudo code for the TwentyOneGame application start Welcome the user to the game ( message read from file ) Declare named constants - NUM_SIDES = 6, WINNING_TOTAL = 21 Declare local variables - computerTotal = 0, userTotal = 0, again, input Create two Die objects die1, die2 to represent the game dice. Create keyboard for user's keyboard input. Display the introduction. Do output, does the user want to roll the dice? Read a character as again if again is yes then //ignore case of again Roll the dice for the user. Increment the user's total points. Roll the dice for the computer. Increment the computer's total points. Display the user's total points. endif while user wants to roll the dice, and the user's total does not exceed 21. Display the totals. if user total is less than or equal to 21 then if user points larger than computer points or the computer points larger than 21 Display, Congratulate the user for winning and write the same message to the output file. else Display, the user did not win the game and write the same message to the output file. endif else Display, the user did not win the game and write the same message to the output file. endif Display the thank you message, let the user know what game they played and remined them to visit your website and the output file name/location. stopJava Code A Game of 21 Write a program that uses the Die class that was presented in Chapter 4 to 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 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 if he or she wants to roll. (Use the Die class that was demonstrated in Chapter 4 to simulate the dice). 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 whoever the player with the most points without going over 21 wins
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started