Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java program that uses the Die class that was presented in this chapter to play a simple dice game between the computer and

Write a Java program that uses the Die class that was presented in this chapter to play a simple dice game between the computer and the user. The program should create two instances of the Die class (each a 6-sided die). One Die object is the computers die, and the other Die object is the users die. The program should have a loop that iterates 10 times. Each time the loop iterates, it should roll both dice. The die with the highest value wins. (In case of a tie, there is no winner for that particular roll of the dice.) As the loop iterates, the program should keep count of the number of times the computer wins, and the number of times that the user wins. After the loop performs all of its iterations, the program should display who was the grand winner, the computer or the user.

file name should be DieDemo.java

(This file should contain both Die and DieDemo classes)

Please note that the output of your program will be different each time because we are using random class to generate random numbers.

Test case:

Roll #1: The computer rolled a 2 and the user rolled a 4 The user won this round!

Roll #2: The computer rolled a 1 and the user rolled a 3 The user won this round!

Roll #3: The computer rolled a 4 and the user rolled a 6 The user won this round!

Roll #4: The computer rolled a 3 and the user rolled a 3 Tie!

Roll #5: The computer rolled a 3 and the user rolled a 2 The computer won this round!

Roll #6: The computer rolled a 1 and the user rolled a 4 The user won this round!

Roll #7: The computer rolled a 5 and the user rolled a 4 The computer won this round!

Roll #8: The computer rolled a 2 and the user rolled a 5 The user won this round!

Roll #9: The computer rolled a 5 and the user rolled a 3 The computer won this round!

Roll #10: The computer rolled a 1 and the user rolled a 4 The user won this round! The user won a grand total of 6 times The computers won a grand total of 3 times

The user is the grand winner!!!

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

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago