Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Having a problem writing a program in java, cathat that would simulate two players rolling 6-sided dice. The player who rolls higher number wins. If

Having a problem writing a program in java, cathat that would simulate two players rolling 6-sided dice. The player who rolls higher number wins. If both players roll the same number, then it is a tie. Use class Random to generate a random integer between 1 and 6 inclusive. This will simulate a dice roll. Read an integer from input and use it as a seed when the Random object is created.

Your program should do the following:

read an integer from input,

create a Random object using the integer read from input as the seed,

simulate 1st payer's dice roll by generating a random integer between 1 and 6 inclusive,

print the number rolled by the 1st player,

simulate 2nd payer's dice roll by generating a random integer between 1 and 6 inclusive,

print the number rolled by the 2nd player,

if both players roll the same number, then print "It is a tie!"

if the 1st player rolled higher number, print "1st player wins!"

if the 2nd player rolled higher number, print "2nd player wins!"

Example 1: If the input is:

2 

then the the Random object is created with a seed value of 2 and the output is:

First player rolled 5 Second player rolled 1 1st player wins! 

Example 2: If the input is:

23 

then the the Random object is created with a seed value of 23 and the output is:

First player rolled 2 Second player rolled 3 2nd player wins! 

Example 3: If the input is:

8 

then the the Random object is created with a seed value of 8 and the output is:

First player rolled 5 Second player rolled 5 It is a tie!

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

Recommended Textbook for

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions

Question

What is project success?

Answered: 1 week ago