Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I request the expert don't copy and paste the answer from other question and please use basic java with scanner class. Program it for two

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

I request the expert don't copy and paste the answer from other question and please use basic java with scanner class. Program it for two players only. See sample output and program.

The Coin class should have the following methods: A no-arg constructor that randomly determines the side of the coin that is facing up ('heads' or 'tails') and initializes the sideUp field accordingly. A void method named toss that simulates the tossing of the coin. When the toss method is called, it randomly determines the side of the coin that is facing up ('heads' or 'tails') and sets the sideUp field accordingly. A method named getSideUp that returns the value of the sideUp field. . Secondly, you will implement the 'Heads or Tails' game. This game is meant for two or more players. In this game, the players take turns flipping a coin. Before the coin is flipped, players should guess if the coin will land face up or face down. If a player guesses correctly, then the player is awarded one point. If a player guesses incorrectly, then the player will lose a point. The first player to score three points is the winner. Write a program named HeadsOrTailsGame.java that simulates the game being played by two players. Use the Coin class that your previously wrote to simulate the coin. Also write the player class to simulate the players. Next a simple run is shown of this application: Enter the first player's name: John Enter the second player's name: Mary Round 1 Start! John guessed heads. Mary guessed tails. The coin was tossed. The coin landed on tails. John guessed incorrectly. John lost a point. Mary guessed correctly. Mary was awarded a point. John has -1 point (s). Mary has 1 point (s). Round 2 Start! John guessed heads. Mary guessed heads. The coin was tossed. The coin landed on heads. John guessed correctly. John was awarded a point. Mary guessed correctly. Mary was awarded a point. John has 0 point (s). Mary has 2 point (s). Round 3 Start! John guessed tails. Mary guessed tails. The coin was tossed. The coin landed on heads. John guessed incorrectly. John lost a point. Mary guessed incorrectly. Mary lost a point. John has -1 point (s). Mary has 1 point (s). Round 4 Start! - John guessed heads. Mary guessed tails. The coin was tossed. The coin landed on heads. John guessed correctly. John was awarded a point. Mary guessed incorrectly. Mary lost a point. John has 0 point (s). Mary has 0 point (s). Round 5 Start! - - John guessed tails. Mary guessed tails. The coin was tossed. The coin landed on tails. John guessed correctly. John was awarded a point. Mary guessed correctly. Mary was awarded a point. John has 1 point (s). Mary has 1 point (s). Round 6 Start! John guessed heads. Mary guessed tails. The coin was tossed. The coin landed on heads. John guessed correctly. John was awarded a point. Mary guessed incorrectly. Mary lost a point. John has 2 point (s). Mary has 0 point (s). Round 7 Start! - - - - John guessed tails. Mary guessed heads. The coin was tossed. The coin landed on tails. John guessed correctly. John was awarded a point. Mary guessed incorrectly. Mary lost a point. John has 3 point (s). Mary has -1 point (s). Game Over John is the 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

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

600 lb 20 0.5 ft 30 30 5 ft

Answered: 1 week ago

Question

7. It is advisable to do favors for people whenever possible.

Answered: 1 week ago

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago