Write a java program consisting of pigdriver and pig

Assignment Help JAVA Programming
Reference no: EM131308623

IMPORTANT:

use JGRASP for editing.

Objectives - At the conclusion of this assignment students will have demonstrated that they can:

Validate input data from a keyboard.

Use loops to repeat actions in a program

Use a Random number generator.

Organize operations into individual methods.

Properly format output to specification.

Do everything necessary to create, debug, and run a java program.

Use comments to delineate each section of the program.

Adhere to a Java Style Guide.

READ AND FOLLOW DIRECTIONS!!!!!

Background

The game of Pig has many variants. In this variant, a single die is used to play a game between the human and the computer. The goal is to be the first to reach 100 points by rolling the die. A player may choose to roll the die any number of times. Each time the die is rolled the value of the die face is added to the player's turn score. If a player relinquishes the die to their oponent, all turn points are added to the person's bank. As soon as the points in the person's turn and their bank reach 100 points, that player wins. The catch in all of this is that if a 1 is rolled, the player loses all of their turn points and play automatically passes to the other player. So the idea is to not be too "piggy" and "hog" the die, but to relinquish control when there are "enough" points in the turn to bank.

In this assignment, you will use a Random object as the "die" which will produce random numbers in the range of 1-6 to represent the die faces. Each player will use this same die.

Player 1 will be a human player and will always go first. Player 2 will be the computer and will always go second. The goal of the human player is to beat the computer player.

Requirements

PART A-There is no part A for this PA.

PART B - Submitted to WebCAT.

You will write a Java program consisting of PigDriver and Pig.java, that must:

Display a welcome message, "Let's Play Pig"

Display a blank line

Prompt for the name of the human player.

Prompt for the name for the computer player.

Display a blank line.

Display the human player name with the line "%s's turn" where the substitution is the name of the player.

Display a blank line.

Display the prompt, "Roll(Y/N)? ". There is one space after the ?.

If the player answers any variant of Y ("Y" or "y") "roll" the die and display the result. The result should be in the form of :(%s Roll: %d Turn: %d Score: %d\n", name, roll, turn, score), where roll is the value for that die roll, turn is the total points for this turn, and score is the total score for this player for all turns. This result should end with the new line character.

If the player answers the roll prompt with anything other than a variant of Y, turn passes to the computer player.

For the computer player, "throw" the dice and display the result of the roll in the same format as the human player. Since the computer cannot "choose" whether or not to continue, we will use the algorithm that if the computer accrues 12 or more points, their turn is over. Play will return ot the human player at that point.

Play ends when either player reaches 50 points. (There should be no turns after the human or computer player reaches 50).

Display a blank line and then the message "%s wins!" where the substitution is the name of the winning player.

See the sample dialog found here: GameDialog.txt

Special requirements: A roll of 1 is poison. If the die roll is a 1, then the player who rolled that die will lose all of their turn points. If a player chooses to end their turn (the computer at 12 or more points, the human by choosing n), the turn points go into their total score bank and cannot be lost. For example, if a player took a turn and accrued 12 points, then relinquished their turn to the computer, those 12 points become part of the permanent score. If the player takes another turn and accrues 15 points and then throws a 1, they lose the 15, but they still have the 12 from the prior turn.

Part B Structure

PA4.java is being given to you. It will bring a seed value in as a command line argument. See RandomLesson in the material for this unit and the demo in class. It will create a Random generator and pass that generator to PigGame's playGame method.

A PigGame starter is being given to you. PigGame.java has some "global variables" or in object terms, these are known as attributes. Since they are defined inside the class but outside of any method, their scope is to be visible in any method. So for example, when you want to add the turn points to the player's score, you will use the humanScore variable. These attributes are all initialized to 0 or null for reference types.

PigGame will have the following required methods:

public int playGame(Random randGen) - controls the action of the game. It takes in a Random object and returns nothing. It should instantiate the Scanner object so that one Scanner can be used throughout the game.

public void printScore(String name, int roll, int turn, int score) - prints the current state of the game after each player throws the die. The name is of the player to report, the roll is the value of the current roll, the turn is the score for that turn including this current roll and the score is the score as of this roll (turn + previous score). Note that you should not update the score in playerTurn since they may lose those points.

public int playerTurn() - controls one complete turn for the human player. It should return the turn score for the player.

public int computerTurn() - controls one complete turn for the computer player. It should return the turn score for the computer.

You may add additional methods to PigGame.java.

Reference no: EM131308623

Questions Cloud

Crimped by recession from bloomberg business : Read the article, Outsourcing Gets Crimped by Recession from Bloomberg Business.  Answer the following questions in your discussion board posting base on this article:
Which market imperfections would be most relevant : If Intel were to increase its debt by $1 billion and use the cash for a share repurchase, which market imperfections would be most relevant for understanding the consequence for Intel's value? Why?
What will be the annual net savings : No more Books financial management expects that collections will be accelerated by 1 day if the eastern region is divided. Should the company proceed with the new system? What will be the annual net savings? Assume that the T-bill is 5 percent ann..
Propose a vision and mission of the team : Propose a vision and mission of the team. Describe the framework for how the data will be utilized in order to inform decision making for the firm.
Write a java program consisting of pigdriver and pig : You will write a Java program consisting of PigDriver and Pig.java, that must Display a welcome message, "Let's Play Pig", Display a blank line and Prompt for the name of the human player.
Determine the the frequency of the wave : EEE 303 Assignment. The electric field intensity of a uniform plane wave propagating in free space is known to be 377e-j0.866ze-j0.5y ax V/m. It strikes a dielectric medium (εr = 9) at 30° with respect to the normal to the plane interface. Determine ..
Which of your friends should purchase the municipal? bond : Three? friends, Jodie,? Natalie, and? Neil, have asked you to determine the equivalent taxable yield on a municipal bond. The? bond's current yield is 3.71 percent with five years left until maturity. Assuming a similar AAA corporate bond yields 4.15..
Should the company proceed with the new system : Should the company proceed with the new system? What will be the annual net savings? Assume that the T-bill is 5 percent annually?
How much will you have at the end of four years : If the account pays 4.30 percent annually, how much will you have at the end of four years?

Reviews

Write a Review

JAVA Programming Questions & Answers

  What is the output of the following program explain

What is the output of the following program? Explain. Explain the meaning of the reserved word this and why it is necessary in the class below. Will the class compile without using this

  Qr codes are a popular way

QR codes are a popular way to encode data for easy reading by computerized cameras. True QR codes contain error correction, format specifiers, version information, and a size variable layout that makes them harder to decode and process

  Define a class called counter

Define a class called Counter. An object of this class is used to count things, so it records a count that is a non negative whole number. Include methods to set the counter to 0, to increase the count by

  Implement a class person with two fields name and age

Implement a class Person with two fields name and age, and a class Car with three fields

  Write a java program that creates 3 threads

Write a Java program that creates 3 threads each of them performing 10 reading/writing to the shared location. Use a random number generator to decide if the request is reading or writing

  Elements of a column of a two-dimensional array

When processing all the elements of a column of a two-dimensional array, what possible runtime error do we have do worry about that the number of column elements may not be constant across all rows.

  1obtaining the new script download and save the attached

1.obtaining the new script download and save the attached comment cgi mailer script form-mail.pl to your servers

  Create java servlets

Create a new JSON "view" (e.g., a JSP page that only displays the JSON representation of the data)

  Program that inputs a degree of difficulty

Write a computer program that inputs a degree of difficulty and seven judges' scores and outputs the overall score for that dive. The program should ensure that all inputs are within the allowable data ranges.

  Write a class house that correctly compiles and runs

Write a class House that correctly compiles and runs with the following TestHouse code. You cannot change a single thing in the TestHouse class,

  Write a java program that will play connect four

Write a java program that will play connect four - Must be a simple program no applets, jframes.

  How to track password-cracking software

Imagine you are a digital forensic investigator for a healthcare organization. You learn from your internal information security department that an employee has been using password-cracking software to access confidential customer insurance inform..

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