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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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