Question: a. You created a Die class that you can use to instantiate objects that hold one of six randomly selected values. Modify this class so

a. You created a Die class that you can use to instantiate objects that hold one of six randomly selected values. Modify this class so its value field is rotected instead of private. This will allow a child class to access the value. Save the file as Die.java. 

b. Create a LoadedDie class that can be used to give a player a slight advantage over the computer. A LoadedDie never rolls a 1; it rolls only values 2 through 6. Save the file as LoadedDie.java. 

c. Create a program that rolls two Die objects against each other 1,000 times and counts the number of times the first Die has a higher value than the other Die. Then roll a Die object against a LoadedDie object 1,000 times, and count the number of times the Die wins. Display the results. Save the application as TestLoadedDie.java. Figure 10-31 shows two typical executions.

With two regular dice, the first die won 421 times out of 1000 With one die and one loaded die, the first die won 247 ti

With two regular dice, the first die won 403 times out of 1000 With one die and one loaded die, the first die won 293 ti

With two regular dice, the first die won 421 times out of 1000 With one die and one loaded die, the first die won 247 times out of 1000 With two regular dice, the first die won 403 times out of 1000 With one die and one loaded die, the first die won 293 times out of 1000

Step by Step Solution

3.53 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a public class Die protected int value private static final int HIGHESTDIEVALUE 6 private static fin... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Programming Questions!