Java Programming I on YouTube:
https://www.youtube.com/playlist?list=PLLIqcoGpl73iaXAtS_-V_Xdx3mhTzPwb5
In this assignment you write a Java program that rolls two dice and displays the results. First, ask the user about the type of dice they want to roll. For example, traditional die that looks like a cube has six sides. Alternatively, there could be many other types of dice -- 4, 6, 8, 12-sided, and so on:
Have your program ask the user how many sides they want on a die. Make sure to validate the user input. Decide what should be the minimal and maximum number of sides allowed.
In a loop, ask the user if they want to roll the dice. If the answer is anything but "Y" or "y", exit the program.
Have a Java class encapsulating the functionality of a die. The die should be configurable according to the number of sides.
Have another Java class that represents a pair of dice. The pair of dice should construct the two dice with the number of sides specified at the beginning of the program.
Note:
It is required that your implementation has a minimum of two Java classes:
one for a die,
another for a pair of dice.
Otherwise there will be a 15 pts deduction off your grade. Feel free to add other Java classes as necessary.
Dice rolling can call Math.random() method, which returns a double value between 0.0 and 1.0. Multiplying the result by an integer and then casting it to an int yields a random number in the range between zero and the number by which you multiplied (but not including the upper boundary itself.) For example,
// Compute random number from zero to 5: int maxNum = 6; int randomValue = (int) ( Math.random() * maxNum );
You can add 1 to the formula in order to shift the random value into the range between 1 and the maxNum:
// Compute random number from 1 to 6: int maxNum = 6; int randomValue = 1 + (int) ( Math.random() * maxNum );
The main method should create the pair of dice, roll the dice, and display the sum of the values rolled. For example, if the values rolled on the dice were 5 and 3, the display format should be
5 + 3 = 8
Print a special meaning for the combinations yielding 2, 7, and 12. For example,
1 + 1 = 2 snake eyes! 3 + 4 = 7 craps! 6 + 6 = 12 box cars!
Feel free to expand and add your own features, if you'd like.
Before submitting, ZIP your src folder and submit as a single ZIP archive.
PLEASE DO NOT send any NetBeans projects or compiled .class files. I only need your Java source code to grade this assignment.
Go to Java Programming I website.
On the Main Menu, follow the link to Weekly Assignments, click a6: submit, and upload your ZIP file with Java source.