/* Dice.java * Simulates rolling two dice, prints the values out (uses random number generator) * CS230 Lab 1 * Written by: CS230 * Modified by: * Modified date:spet 2019 */ import java.util.Random; // To use the Random class for random number generation public class Dice { /* * Simulates rolling a single die * @returns an integer between 1 and 6 */ public static int roll() { Random rand = new Random(); int num = rand.nextInt(6); // [0-6), i.e 0, 1, 2, 3, 4, or 5 num = num + 1; // [1-6] like a real die return num; } public static void main (String [] args) { //call helper method to roll two dice int die1 = roll(); int die2 = roll(); System.out.println("You rolled a "+ die1 +" and a "+ die2+ "."); /* Optional: use a for loop to roll the pair of dice multiple times: int die1, die2; // declare variables, assign values in the loop for (int i=1; i<=10; i++) { // will loop 10X die1 = roll(); die2 = roll(); System.out.println("You rolled a "+ die1 +" and a "+ die2+ "."); }// closes for loop */ } }