Requirementspig is a folk jeopardy dice game with simple

Assignment Help JAVA Programming
Reference no: EM13370822

Requirements

Pig is a folk jeopardy dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 ("pig") is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn, the player is faced with two decisions:

•roll - If the player rolls a

1: the player scores nothing and it becomes the opponent's turn.
2 - 6: the number is added to the player's turn total and the player's turn continues.

•hold - The turn total is added to the player's score and it becomes the opponent's turn.

Write a program that allows a single player to practice the game (that is, there will be no opponent, just a single player). Play 5 turns in the game to get a total score for the player. Refer to the sample output below for a detailed example.

Declare and use the following methods appropriately. You will only receive full credit if these methods are properly used in your solution.

•public static int roll();
oGenerates a random dice roll value and returns it.

•public static int playTurn();

oPlays a single turn by:
-Roll a the die using the roll() method.
-If the value is 1, the turn total is reset to 0.
-If the value is not 1, add the value to the player's turn score.
-Print the rolled value and turn total using the printRollResult(...) method.
-If the value is 1, end the turn.
-If the value is not 1, prompt the player to roll again or hold using the isHold() method. If the user selects to roll again, repeat this process.

•public static void printRollResult(int rollValue, int turnTotal)
oDisplay the rolled value and turn total.

•public static boolean isHold();
oPrompt the user to 1. Roll again or 2. Hold.
oReturn true if the user selects to hold.

The output must be:
•For each turn, print a line with "Turn:" and the turn number.
•For each roll, print a line with "Roll value:" and the random die roll value (1-6) followed by "Turn total:" and the turn total (0 if the user rolled a pig).
•For each roll that isn't a 1 (i.e. the pig), a prompt to hold or roll again.
•At the end of the game, print "Game total: " and the total score.

Be sure to use proper coding conventions including indentation, constants, and comments. Be sure to use method level comments and JavaDoc style.

Formula
A random die roll can be simulated with the statement:

int roll = (int) (Math.random() * 6) + 1;

Hint
The main() method will call the playTurn() method 5 times, summing the results into a game total. The playTurn() method will call the roll(), printRollResult(), and isHold() methods.

Example Program Execution

Game 1 Example
Turn: 1
Roll value: 3
Turn total: 3
1) Roll again or 2) Hold? 1
Roll value: 5
Turn total: 8
1) Roll again or 2) Hold? 1
Roll value: 2
Turn total: 10
1) Roll again or 2) Hold? 1
Roll value: 3
Turn total: 13
1) Roll again or 2) Hold? 1
Roll value: 3
Turn total: 16
1) Roll again or 2) Hold? 1
Roll value: 5
Turn total: 21
1) Roll again or 2) Hold? 2

Turn: 2
Roll value: 6
Turn total: 6
1) Roll again or 2) Hold? 1
Roll value: 2
Turn total: 8
1) Roll again or 2) Hold? 1
Roll value: 4
Turn total: 12
1) Roll again or 2) Hold? 1
Roll value: 5
Turn total: 17
1) Roll again or 2) Hold? 1
Roll value: 6
Turn total: 23
1) Roll again or 2) Hold? 2

Turn: 3
Roll value: 3
Turn total: 3
1) Roll again or 2) Hold? 1
Roll value: 3
Turn total: 6
1) Roll again or 2) Hold? 1
Roll value: 2
Turn total: 8
1) Roll again or 2) Hold? 1
Roll value: 4
Turn total: 12
1) Roll again or 2) Hold? 1
Roll value: 6
Turn total: 18
1) Roll again or 2) Hold? 1
Roll value: 1
Turn total: 0

Turn: 4
Roll value: 2
Turn total: 2
1) Roll again or 2) Hold? 1
Roll value: 4
Turn total: 6
1) Roll again or 2) Hold? 1
Roll value: 4
Turn total: 10
1) Roll again or 2) Hold? 1
Roll value: 3
Turn total: 13
1) Roll again or 2) Hold? 1
Roll value: 3
Turn total: 16
1) Roll again or 2) Hold? 2

Turn: 5
Roll value: 5
Turn total: 5
1) Roll again or 2) Hold? 1
Roll value: 2
Turn total: 7
1) Roll again or 2) Hold? 1
Roll value: 2
Turn total: 9
1) Roll again or 2) Hold? 1
Roll value: 4
Turn total: 13
1) Roll again or 2) Hold? 1
Roll value: 6
Turn total: 19
1) Roll again or 2) Hold? 1
Roll value: 6
Turn total: 25
1) Roll again or 2) Hold? 1
Roll value: 3
Turn total: 28
1) Roll again or 2) Hold? 2

Game total: 88
Game 2 Example
Turn: 1
Roll value: 4
Turn total: 4
1) Roll again or 2) Hold? 1
Roll value: 3
Turn total: 7
1) Roll again or 2) Hold? 1
Roll value: 5
Turn total: 12
1) Roll again or 2) Hold? 1
Roll value: 3
Turn total: 15
1) Roll again or 2) Hold? 1
Roll value: 6
Turn total: 21
1) Roll again or 2) Hold? 2

Turn: 2
Roll value: 5
Turn total: 5
1) Roll again or 2) Hold? 1
Roll value: 2
Turn total: 7
1) Roll again or 2) Hold? 1
Roll value: 2
Turn total: 9
1) Roll again or 2) Hold? 1
Roll value: 5
Turn total: 14
1) Roll again or 2) Hold? 1
Roll value: 2
Turn total: 16
1) Roll again or 2) Hold? 1
Roll value: 4
Turn total: 20
1) Roll again or 2) Hold? 1
Roll value: 3
Turn total: 23
1) Roll again or 2) Hold? 1
Roll value: 4
Turn total: 27
1) Roll again or 2) Hold? 2

Turn: 3
Roll value: 6
Turn total: 6
1) Roll again or 2) Hold? 1
Roll value: 1
Turn total: 0

Turn: 4
Roll value: 1
Turn total: 0

Turn: 5
Roll value: 1
Turn total: 0

Game total: 48
Notes
The Game of Pig by Todd Neller and Clif Presser inspired this assignment.

Reference no: EM13370822

Questions Cloud

1 what is mm capital structure theory with corporate taxes : 1. what is mm capital structure theory with corporate taxes but no personal taxes and bankruptcy costs?2. what is the
Problem aa savings account object holds a nonnegative : problem aa savings account object holds a nonnegative balance and provides depositk and withdrawk methods where
Assignment problems1 suppose the revenue for a firm is : assignment problems1. suppose the revenue for a firm is 2500000. its cost of goods sold is 85000 and its average
Give an example of a good decision you made that resulted : give an example of a good decision you made that resulted in a bad outcome or an example of a bad decision you made
Requirementspig is a folk jeopardy dice game with simple : requirementspig is a folk jeopardy dice game with simple rules two players race to reach 100 points. each turn a player
A particle moving in a straight line with constant : a particle moving in a straight line with constant accelaration is having initial velocity of 10 ms. after some time
Terry marks is a well-known architect he wants to start his : terry marks is a well-known architect. he wants to start his own business and convinces rob norris his cousin and a
Computational biophysics and nanoscale simulationsnamd is a : computational biophysics and nanoscale simulationsnamd is a parallel object-oriented molecular dynamics code designed
Management research relies upon a variety of different data : management research relies upon a variety of different data collection methods such as survey interview and

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a program in which a ball is released

Write a program in which a ball is released from a user-defined height and free-falls to the ground. The ball is pulled by earth's gravity of 9.8 m/sec 2 . Assume that each pixel represents 1 cm. Once the ball hits the ground

  Assignmentwrite a gui-based application that allows a user

assignmentwrite a gui-based application that allows a user to play a simple trivia game. the game should have 5

  Sorting routine adopted in the java api for arrays.sort()?

What is the sorting routine adopted in the Java API for Arrays.sort()? How different is it from the sorting routine we discussed in class? Is it better? Explain your answers in short clear sentences.

  Development of a graphical user interface

Understand actual communication with an SMTP server can be achieved using TCP Sockets and understand the development of a graphical user interface (GUI) and use of event handling.

  User enter a series of numbers

Design a java program with a loop that lets the user enter a series of numbers. The user should enter - 99 to signal the end of the series. After all the numbers have been enter been entered, the program should display the largest and smallest number..

  Finding java code error

Indicate in the given code segment if an error occurs. If so, point to whether it is syntax, runtime or logic and how you would fix it.

  Calculate the percent of kcal from each macronutrient

Calculate the percent of kcal from each macronutrient and the percent of kcal by fluids.

  Write a recursive boolean method named ismember in java

Write a recursive boolean method named isMember in Java. The method should accept three arguments: an array, a value to search for, and the size of the part of the array being searched.

  Implementation the two classes

Program Specifications: In the new implementation, the two classes, Student and Grades, are defined with the following operations/methods.

  Please write the code in java nbsprecursionimplement a

please write the code in java nbsprecursionimplement a subsetgenerator that generates all subsets of the characters of

  Adt for a two color double stack adt consists of two stacks

design an adt for a two color double stack adt that consists of two stacks one red and one blue and has its operations color coded versions of the regular stack adt operations.

  Java program to write-read data from user using i-o function

Write java program to write and read data from user using I/O functions. Describe class with data members name[20],emp_id,basic pay,net pay.calculate all the allowances.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd