ICS 111 Homework Assignment H01: Simulate a pair of dice.

1) Write a program that simulates rolling a pair of dice. You can simulate rolling one die by (solution) choosing one of the integers 1, 2, 3, 4, 5, or 6 at random. The number you pick represents the number on the die after it is rolled. As pointed out in Section 2.5, the expression

(int)(Math.random()*6) + 1

does the computation to select a random integer between 1 and 6. You can assign this value to a variable to represent one of the dice that are being rolled. Do this twice and add the results together to get the total roll. Your program should report the number showing on each die as well as the total roll. For example:

The first die comes up 3
The second die comes up 5
Your total roll is 8

2) Modify your program to simulate two 20 sided dice.

3) Bonus Modify your program to ask the user for the number of sides for the dice, then simulate rolling them.

Turning in the Assignment

The assignment is due on Friday at 11:55pm. You may turn it in early.

  1. Conduct a personal review of your code before turning it in. Does your code follow the Java Coding Standard?

    Is it clear and well commented?

  2. Test your code.

    • Does it produce the correct output? For regular and 20 sided dice?
  3. Sign into Laulima, then navigate to the ICS111 site. In the left hand side of the site, there is an Assignments tab/link. Click on it and view all of the posted assignments. Select the assignment that you want to turn in and attach your files and accept the honor pledge to submit the assignment.