• Ask an Expert
• Get a Professional Answer
• 100% Satisfaction Guarantee
Raj, Engineer
Category: Homework
Satisfied Customers: 1290
Experience:  4 + Experiance in IT Industry
16752232
Type Your Homework Question Here...
Raj is online now

# Write a program that allows a single Player (the user) to play

### Resolved Question:

Write a program that allows a single Player (the user) to play a simple two dice game of chance against a single Opponent (the computer).

Game Description:

There is a single Player (human), with two dice.

There is a single Opponent (computer), with two dice.

Each die is six sided, and each of its sides is labeled with a unique number from 1 to 6, we will call this the value of the die.

A game is made up of rounds, a single round is played as such:

The computer Opponent rolls it two dice.

The dice are displayed.

The Player rolls their two dice.

The dice are displayed

A determination is made as to who won the round, this determination is made via the following rules:

Larger values beat smaller values, same values are a tie.

A pair is when both dice have the same number on their top faces, the value of the pair is this common value.

A non-pair is then when both dice have a different number on their top faces, the major die is the one with the larger value and the minor die the one with the lesser value.

Any pair beats any non-pair.

Any two pairs are compared by their respective pair values.

Any two non-pairs are first compared by their major die values and only in the case of a tie in majors, are compared by their minor die values.

The result of the round (with respect to the Player) is announced.

The result of the round (with respect to the Player) is tallied, by increasing the number of player wins, ties, or loses by one.

The player decides if they wish to play another round.

When the game is over, the results of the game (how many rounds the player won, tied and lost) are announced.

Rules and Requirements:

You must model a pair of dice as two integers (one for each of the die) named major and minor respectively.

You must have one pair of die designated for the Opponent and one pair of die designated for the Player.

The value of the major die must be greater than or equal to the value of the minor die. Each time either or both are modified you must verify this condition and re-order them if necessary.

Given the following method heading, you must write the corresponding definition for a void return method that displays a brief accounting of the rules and format of your game.

// displays a brief accounting of the rules and format of the game
public static void welcome()

Given the following method heading, you must write the corresponding definition for a int return method that generates and returns a random number in the range of low to high inclusive.

// returns an int in the range [low, high]
public static int rollDie(int low, int high)

Given the following method heading, you must write the corresponding definition for a int return method that returns the larger of d1 and d2.

public static int majorDie(int d1, int d2)

Given the following method heading, you must write the corresponding definition for a int return method that returns the smaller of d1 and d2.

public static int minorDie(int d1, int d2)

Given the following method heading, you must write the corresponding definition for a void return method that prints the pair of dice (d1 and d2) to the screen, in some reasonable report format.

public static void printDice(int d1, int d2)

Given the following method heading, you must write the corresponding definition for a boolean return method that returns true if and only if d1 == d2.

public static boolean isPair(int d1, int d2)

Given the following method heading, you must write the corresponding definition for a int return method that determines the result of a single round of the game, (with respect to the Player).

// return: -1 -> Player lost; 0 -> tie; 1 -> Player won
public static int result(int oMajor, int oMinor, int pMajor, int pMinor)

Given the following function heading, you must write the corresponding definition for a void return method that generates a reasonable report of a game's outcome statistics.

// Report the games outcome statistics
public static void report(int wins, int ties, int loses)

Your program may use additional methods if desired.

Sample run(s):

miller.cs: Sample9

Welcome to Computer Dice
---------------------------------------------
Your opponent will first roll their two dice.
Next You will roll your two dice.

The outcome of each round will be based on
the values of your dice - high beats low,
pairs beat non-pairs.
---------------------------------------------

Opponent
--------
4 3

Player
--------
4 1
Sorry, you lose!

Do you wish to play again [y, n] : y

Opponent
--------
6 3

Player
--------
5 1
Sorry, you lose!

Do you wish to play again [y, n] : y

Opponent
--------
2 2

Player
--------
4 1
Sorry, you lose!

Do you wish to play again [y, n] : y

Opponent
--------
Submitted: 4 years ago.
Category: Homework
Expert:  Raj replied 4 years ago.
Hi there,

I will be helping yoi with the solution.
Can you please specify the programming language to be used along with the deadline?

Thank you
Customer: replied 4 years ago.
java and tomorrow at 5pm cst
Expert:  Raj replied 4 years ago.
I am sending an underprice reporting the new price based on urgency and amount of work to be done.
Customer: replied 4 years ago.
ok, how much?
Expert:  Raj replied 4 years ago.
I sent the underprice report for \$40
Customer: replied 4 years ago.
ok, sounds good
Expert:  Raj replied 4 years ago.
Ok ask the cistomer care to change the price to our agreed value..
Customer: replied 4 years ago.
Ok, I just did that. Will my answer be ready by 5pm today? Even if customer care doesn't get this fixed in time i can always just add a \$20 tip to make the value \$40.
Expert:  Raj replied 4 years ago.
Ok no problem you can add tip....
Also I will be providing the .java file. Will you be able to run it on your side?

Let me know about that...
Which software do you use....
Customer: replied 4 years ago.
Yes, I have eclipse
Expert:  Raj replied 4 years ago.
Ok got it
Expert:  Raj replied 4 years ago.
Ok at the End of Sample RUN I think something went missing.
Can you please post the sample run i.e. the last part of Question Once again....

Thank you
Expert:  Raj replied 4 years ago.
THIS ANSWER IS LOCKED!

You need to spend \$3 to view this post. Add Funds to your account and buy credits.
Raj and 3 other Homework Specialists are ready to help you