a. Create a Die class that you can use to instantiate objects that each hold a value

Question:

a. Create a Die class that you can use to instantiate objects that each hold a value from 1 through 6. The field that holds the value of the Die should be protected, which 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 9-72 shows two typical executions.


Data from in Figure 9-72

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question

Java Programming

ISBN: 9780357673423

10th Edition

Authors: Joyce Farrell

Question Posted: