Question
In the board game Risk, each player's goal is to conquer the world by occupying every country. The play involves neighboring countries fighting one or
In the board game Risk, each player's goal is to conquer the world by occupying every country. The play involves neighboring countries fighting one or more battles. Most battles in Risk involve four armies, two from the attacking country, and two from the defending country.
The process for fighting a battle involves the attacker rolling three dice, and the defender rolling two dice. We will assume these are typical 6-sided dice with values 1 through 6, inclusive. The highest die of the attacker is compared with the highest die of the defender, and the second-highest die of the attacker is compared with the second-highest die of the defender. If both of the attacker's dice are higher than the defender's, the attacker wins the battle and the defender loses two armies. If both of the defender's dice are higher than or equal to the attacker's, the defender wins the battle and the attacker loses two armies. Otherwise, each player loses one army. Some examples follow:
Attacker | Defender | Comparison | Result |
1 5 4 | 4 2 | attacker 5 > defender 4, attacker 4 > defender 2 | attacker wins, defender loses two armies |
4 3 4 | 2 4 | attacker 4 <= defender 4, attacker 4 > defender 2 | tie, each player loses one army |
3 4 3 | 5 3 | attacker 4 <= defender 5, attacker 3 <= defender 3 | defender wins, attacker loses two armies |
Write a class Utilities in the default package containing the following public static methods.
A public static method newDieRoll that has no parameters and returns an int random value between 1 and 6 (inclusive).
Overloaded public static methods bigDie that take either three or two int parameters. bigDie returns an intthat is the largest of its parameter values.
Overloaded public static methods nextBigDie that take either three or two int parameters. nextBigDiereturns an int value that is the second-highest value of its parameters. Note that the second highest value of (5, 4, 5) is 5, since we consider that the highest value is one of the 5s, and the "other" 5 is the second highest. Similarly, the second highest value of (4, 4) is 4; the highest value is one of the 4s, and the second highest is the "other" 4.
A public static method battle. The parameter list for battle is four int values, and they are, in order, attackerHighestDie, attackerSecondHighestDie, defenderHighestDie, defenderSecondHighestDie. The method returns an int value of
1 if the attacker wins the battle and the defender loses two armies
-1 if the defender wins the battle and the attacker loses two armies
0 if there is a tie and the attacker and defender lose one army each.
After the outcome of the simulated battles has been determined, main should
print the percentages of the battles the attacker won, the defender won, and ties.
print the total number of armies lost by the attacker and defender. (Don't forget that the ties also factor into the armies lost.)
The sample output is supposed to come out to be this.
Enter the number of battles to simulate, or -1 to exit.
defender loses 8 armies
attacker loses 2 armies
the attacker wins 80.0 percent of the battles
the defender wins 20.0 percent of the battles
they tie 0.0 percent of the battles
Please put a the code at the end so that I can copy it and use eclipse to write it. Thanks.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started