Write a program to play the pig game against the computer

Assignment Help Computer Engineering
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.

Reference no: EM132210489

Questions Cloud

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

Reviews

Write a Review

Computer Engineering Questions & Answers

  Create a graphical interface using the graphics class

Swing to create a graphical interface, and using the Graphics class for drawing the board, the markers, and line through the winning set of markers.

  Write a c program that finds voltage drop and power

Write a C program that finds voltage drop and power dissipated by a resistance (R) when a current (I) flows through it.

  Why would you use dac instead of mac

Why would you use DAC instead of MAC? Why would you use DAC instead of MAC? Does using MAC without running DAC underneath make any sense?

  Dtproperties and sysdiagrams

Exclude the tables “dtproperties” and “sysdiagrams”. List the column CountOfTable, in which the Table is the chosen table name.

  Determine how many logins occurred for user

Write a perl script, myperlone.pl, to determine how many logins occurred for user "fau563" ?

  Draw a high-level er diagram for the business statement

For each student we want to know their name, date of birth, contact info and GPA. The contact info includes mailing address, email, and telephone.

  Write a statement that makes the control invisible

Suppose an application's GUI has a PictureBox control name myPicture. Write a statement that makes the control invisible.

  Determine the magnitude response of transfer function

The following first-order IIR transfer function has been proposed for clutter removal in MT1 radars (Urk58).

  Create a wbs and enter the tasks in project

Enter realistic durations for each task. Assume you have only four months to complete the project. Take a screen shot of the resulting Gantt chart and paste this into the Word for Windows file.

  Write a command that will tell me the unique files

For example, "favicon.ico" is one. Write a command that will tell me the unique files that have been accessed. All of GET, HEAD, and POST count.

  Dma has been around for a long time and when it was

write a 200- to 300-word short-answer response to the followingdma has been around for a long time and when it was

  What do you mean by sensitivity analysis how would you use

what is a sensitivity analysis? how would you use it in planning for future expansions? what role does this kind of

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