Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pass the Pigs Create a class named PassThePigs. See the UML above (some of the required constants are not listed in the UML.) See this

Pass the Pigs

  1. Create a class named PassThePigs. See the UML above (some of the required constants are not listed in the UML.)

  2. See this Wikipedia article for an explanation of the game.

  3. There are six possible rolls for each pig, listed in the table below. (The picture shows a trotter and a snouter.)

Name

Chance

Score

Sider (side without dot up)

33%

0

Sider (side with dot up)

33%

0

Trotter (pig on 4 feet)

10%

5

Razorback (all 4 feet in the air)

20%

5

Snouter (on nose and two feet)

3%

10

Leaning jowler (on nose, ear, and foot)

1%

15

  1. Create String constants for the six names. (Only three are listed in the UML. Follow the pattern to create the other three.)

  2. Create constants for the six scores. (Only three are listed in the UML. Follow the pattern to create the other three.)

  3. Create six probability constants. (Only three are listed in the UML. Follow the pattern to create the other three.) The actual probability from the table above is built into the difference between successive constants as shown in the parentheses.

    1. Sider without dot: 33 (33%)

    2. Sider with dot: 66 (66 - 33 = 33%)

    3. Trotter: 76 (10%)

    4. Razorback: 96 (20%)

    5. Snouter: 99 (3%)

    6. Leaning jowler: 100 (1%)

  4. The program code is in main.

  5. Create a String variable representing each rolled pig.

  6. Create two score variables: one for a single roll of two pigs, one for the total for the turn - possibly multiple rolls.

  7. Initialize the score for the whole turn (set to 0).

  8. The rest of the program should be in a loop. The loop will represent one turn.

  9. Set the score for this roll to 0.

  10. Create a random number between 0-99 to represent a pig roll. (see section 5.2.)

  11. Use the probability constants (#6 above) as range cutoffs (hint: use if - else if, see section 6.6 Detecting ranges) to:

    1. Assign the appropriate roll name to the pig String variable

    2. Add the appropriate score for this pig to the score for this roll.

  12. Repeat the two steps above (15 & 16) for the second pig. If youre clever, use a loop.

  13. Handle special cases

    1. If the two pigs are different siders, this roll and the total score are set to 0, and the play (and loop) stops. Display Pig out!

    2. If the two pigs are the same, the roll score is doubled

    3. If the two pigs are the same type of sider, this roll score is 1 (not 0.)

  14. Display the score for this roll, the score for the turn.

  15. If the user didnt pig out, ask whether the user wants to roll again.

  16. Use Scanners next() method to get the user input. (Not nextLine().)

  17. Continue the loop until the user says they want to stop (or when a pig out occurs.)

  18. Suggestion: To test that your scoring is correct, temporarily replace the Random classs nextInt method with the Scanner classs nextInt method. Then test with numbers 0-99. Otherwise, you may wait a long time to get a Leaning Jowler!

  19. Submit your .java file.

Sample run

(user input is bold)

Rolling ... Sider(dot) & Sider(dot)

this roll: 1

this turn: 1

Roll again (y/n)? y

Rolling ... Trotter & Trotter

this roll: 20

this turn: 21

Roll again (y/n)? y

Rolling ... Snouter & Razorback

this roll: 15

this turn: 36

Roll again (y/n)? y

Rolling ... Sider(dot) & Razorback

this roll: 5

this turn: 41

Roll again (y/n)? y

Rolling ... Razorback & Sider(no dot)

this roll: 5

this turn: 46

Roll again (y/n)? y

Rolling ... Trotter & Razorback

this roll: 10

this turn: 56

Roll again (y/n)? y

Rolling ... Sider(dot) & Snouter

this roll: 10

this turn: 66

Roll again (y/n)? y

Rolling ... Razorback & Sider(dot)

this roll: 5

this turn: 71

Roll again (y/n)? y

Rolling ... Sider(dot) & Sider(no dot)

Pig out! No score.

Your turn is over.

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

Mastering Big Data Interview 751 Comprehensive Questions And Expert Answers

Authors: Mr Bhanu Pratap Mahato

1st Edition

B0CLNT3NVD, 979-8865047216

More Books

Students also viewed these Databases questions