Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M92063252
  • Price:- $40

Priced at Now at $40, Verified Solution

Have any Question?


Related Questions in Java

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Can someone please help me with the following java

can someone please help me with the following java question The input is an N by N matrix of nonnegative integers. Each individual row is a decreasing sequence from left to right. Each individual column is a decreasing s ...

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment - java program using array of objectsobjectives

Assignment - JAVA Program using array of objects Objectives - This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details - For this assignment, you are required to develop a Menu ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As