Write a program that plays the game of pig

Assignment Help JAVA Programming
Reference no: EM131449924

Programming Assignment: The Game of Pig

The game of Pig is a simple two-player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn, a player rolls a six-sided die:

• If the player rolls a 1, then the player gets no new points and it becomes the other player's turn.

• If the player rolls 2 through 6, then he or she can either

o ROLL AGAIN

or

o HOLD:

At this point, the sum of all rolls is added to the player's score and it becomes the other player's turn.

Write a program that plays the game of Pig, where one player is a human and the other is the computer. When it is the human's turn, the program should show the score of both players and the previous roll. Allow the human to input whether to roll again or hold.

The computer program should play according to the following rules:

• Keep rolling when it is the computer's turn until it has accumulated 20 or more points, then hold.
• If the computer wins or rolls a 1, then the turn ends immediately.

Allow the human to roll first.

Notes

To make your task easier, you should modularize your codes as the following methods:

• staticintusersTurn(intoldTotal): user rolls until they either:

o hold: the turn total is added to the oldTotal and the sum is returned
o roll a 1: the oldTotal is returned

• staticintcomputersTurn(intoldTotal): computer rolls until it either:

o holds (once it has accumulated 20 or more points for this turn): the turn total is added to the oldTotal and the sum is returned
o rolls a 1: the oldTotal is returned

• staticintrollDie(): simulates rolling a die (random number from 1 to 6).

Reference no: EM131449924

Questions Cloud

Find the total present value of those costs : Calculate the cost (inflated at 6%) for each year of college and find the total present value of those costs,
Explain how the company will track sales and receipts : How the company will track sales and receipts, and the application will report in to a central server to collect all the sales data from all the locations.
What is the beta of the firms assets : The risk-free rate equals 7%, and the expected risk premium on the market portfolio equals 7%. What is the firm's WACC? What is the beta of the firm's assets?
How large will your last payment be : Your last deposit, which will occur at the end of Year 6, will be for less than $1,500 if less is needed to reach $10,000. How large will your last payment be?
Write a program that plays the game of pig : Write a program that plays the game of Pig, where one player is a human and the other is the computer. Allow the human to input whether to roll again or hold.
Regarding the short-term trading and bond swap opportunity : Regarding the short-term trading opportunity-What basic trading principle is involved in this situation? Regarding the bond swap opportunity:
Annual discount rate-all cash flows occur at end of year : Assume that the annual discount rate is 15% for all projects, and that all cash flows occur at the end of the year. Please consider each statement independently
Treasury issued ten-year inflation indexed note : the U.S. Treasury issued a? ten-year inflation indexed note with a coupon of 6%. What principal and coupon payment was made on January? 15, 2030?
Prepare the income tax expense section of income statement : prepare the income tax expense section of the income statement for 2014, beginning with the line income before income taxes

Reviews

Write a Review

JAVA Programming Questions & Answers

  How else will you continue to maintain your website

Based on your usability test, what steps will take to update and improve your website? Will you register a domain name and host your website live? If yes, with what host? How else will you continue to maintain your website?

  Discuss how using arrays changes the way

Discuss how using arrays changes the way that your code is organized.

  Write a program that displays a drawing popular hangman game

Write a program that displays a drawing for the popular hangman game, as shown in Figure 15.32(c). draws a sketch for the hangman game.

  Array named peopletypes that can store a maximum

Define a 1-D array named peopleTypes that can store a maximum of 50 integer values that will be entered at the keyboard. Enter a series of 1's, 2's, 3's and 4's into the array, where a 1 represents an infant, a 2 represents a child, a 3 represents..

  Discuss the necessity of designing programs to handle except

Discuss the necessity of designing programs to handle exceptions of various types

  What is the logical expression in your program

Choose two everyday programs you use that utilize different while, do...while, or for loops. Explain which program uses which loop and why that might be. What is the logical expression in your program

  Implement the hierarchy for a university with java classes

Implement the above hierarchy for a university with Java classes and their appropriate relationship. You can go three levels deep in the hierarchy (community member, employee, student, alumnus, faculty, staff). Use your best judgment of instance v..

  Create a java class called samearraysexception

Create a Java class called SameArraysException that extends the Exception class.

  Integer expression evaluator

You must implement a bounded generic Stack class. Represent your Stack using an array to hold the stack content - Integer Expression Evaluator

  Create a new class called dwelling

1 Create a new class called Dwelling that includes the functionality below 2.    The new class has the attributes of: category - dwelling's category (i.e.:"House", "Condo", "Apartment","shach",etc.), type String numberOfBedrooms - the number of bedro..

  Java program for presidential elections

Write a java program for Presidential Elections, the user will enter his votes based on the code for each candidate. The program will add the total votes for each candidate and proclaim the winner whoever got the most number of votes.

  Create a class called month with the given fields and method

Create a class called Month (java file called Month.java) with the (exact) following fields and methods. Create three objects: Month1 one using the first constructor (with no arguments) and Month2.

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