Reference no: EM132210489
Question :
Write a program to play the pig game against the computer. At each turn, the current player will roll a pair of dice and accumulates points.
I'm in a beginers Java class and some if these steps are really confusing to me. Especially step 5. How do you declare boolean variables?
Write a program to play the pig game against the computer. At each turn, the current player will roll a pair of dice and accumulates points.
The goal is to reach to 100 or more points before your opponent does. (For the testing purposes use 30 instead of 100 points) If, on any turn, the player rolls a 1, all the points accumulated for that round are forfeited and the control of the dice moves to the other player.
If the player rolls two 1s in one turn, the player loses all the points accumulated thus far are forfeited and the control moves to the other player.
The player may voluntarily turn over the control of the dice after each roll. Therefore player must decide to roll again (be a pig) and risk losing points, or relinquish control of the dice, possibly allowing the other player to win. Computer is going to flip a coin to choose the first player
Here is the list of the tasks that needs to be done
1. Describe the game by writing a method.
2. Data validation: A method that accepts a Scanner object as its parameter, prompt the user to enter "yes" or "no". as long as the user is not entering a valid input , prompt the user again
3. Flip the coin: This method accepts a Random object and returns" head" or "tail" based on the random number that was generated
4. Roll two dices: this method accepts a Random object. Generates two random number representing one of the numbers on a dice. Returns the sum of the dices.
5. Choose a name for the computer: Come up with 10 different name for the computer. Then select a random name from the list that you created. Return the selected name.
6. Play: this method calls the other methods to play the game
Must declare the following two constants
public static final int POINTS = 40;
publinc static final into FORFEIT_Points = 20;
a. Declare all the needed variables to keep track of the scores for each player, and Boolean variables to indicate who is playing at the moment.
b. Ask the user's name
c. Decide who start the game first by calling one of the methods you created to flip the coin.
d. Write conditional statements to switch the game between the computer and the player based on the dice rolled and overall points. Read the output and the program description to figure out the conditions. You need to use couple while loops: one loop for the human player, one loop for the computer player.
Prompt a user to enter data for an array
: getTotal. This method should accept a one-dimensional array as its argument and return the total of the values in the array.
|
Prepare consolidation worksheet entries for december
: What is the consolidated balance for the Equipment account as of December 31, 2012 - Prepare consolidation worksheet entries for December 31, 2011, and December
|
Determine the number and type of variables
: Write a program that prompts the user to enter a decimal number and then outputs this number rounded to two decimal places.
|
Write about two artworks from the periods
: For this essay, write about two artworks from the periods we read about in Unit VII: Renaissance, Baroque, Impressionist, or Post-Impressionist periods.
|
Write a program to play the pig game against the computer
: Write a program to play the pig game against the computer. At each turn, the current player will roll a pair of dice and accumulates points.
|
Discuss sources of health insurance coverage in home state
: Discuss the sources of health insurance coverage in your home state, or any state of your choosing, for the following groups: Seniors age 65 and older.
|
Find your favorite song about loss and grief on youtube
: Write a few sentences about they ways in which you hear grief and lamenting being portrayed musically? In other words, what does the composer do with rhythms.
|
What might cause an artwork to be censored
: Let's continue our discussion about art and the public by looking more at censorship. Below are some questions to consider. You may answer one or more of them.
|
Compute the times-preferred-dividend-earned ratio
: Compute the times-preferred-dividend-earned ratio for the past three years from the following data taken from firm's financial statements
|