Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Game of Pig has been around for quite a while, requiring just one or two dice to play. Write a program that will allow

The Game of Pig has been around for quite a while, requiring just one or two dice to play. Write a program that will allow you (the "player") to play against the computer. The rules of the game are: (java)

- The first player to accumulate a score of 100 or more wins.

- The human goes first.

- After one roll, a player has the choice to "hold" or to roll again. They can roll as many times as they like unless they get one or two sixes.

- You roll two dice. Certain conditions apply:

- If both dice are sixes the player's total score is set to zero and his turn is over. Ouch!

- If one dice is six, then your turn is over and your turn score is set to zero.

- If both dice match ("doubles"), other than sixes, then you gain twice the sum of the dice, and you must roll again. For example if you rolled two fours, you would gain 16 and then have to roll again.

- For any other dice combination, you just add the dice total to your turn score and you have the choice of rolling again.

- When your turn is over, either because you won, you chose not to roll again or you rolled a six, then your turn sum is added to your accumulated score.

More Info

- Put all methods in a single class along with a main method, where they all need to be declared static. At this point it does not matter if they are declared public or private. There is no required number of methods for this program. Methods should be compact, should minimize code duplication and have a single purpose. If a method is over about 25 lines in length, it is probably too long.

- You can only declare constant class attributes, declared as final static, if you need them. Other, non-constant data items must be moved between methods as arguments or return values. The only exception to this rule is the random number generator object as described below.

In Java

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago