can you please make me a Dice Rolling Simulator The Goal: Like the title suggest
ID: 3667669 • Letter: C
Question
can you please make me a Dice Rolling Simulator
The Goal: Like the title suggests, this project involves writing a program that simulates rolling dice.When the program runs, it will randomly choose a number between 1 and 6. (Or whatever other integer you prefer — the number of sides on the die is up to you.) The program will print what that number is. It should then ask you if you’d like to roll again.For this project, you’ll need to set the min and max number that your dice can produce. For the average die, that means a minimum of 1 and a maximum of 6.You’ll also want a function that randomly grabs a number within that range and prints it.Random random1 = new Random();
Explanation / Answer
Java Program for roll dice is given below:
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
public class rollDice { // Dice class
public static void main(String[] args)
{
int die;
String option = "";
Scanner scan = new Scanner(System.in);
do
{
die = (int)(Math.random()*6) + 1; //used random function to get a number between 1-6
System.out.println("The die comes up with number: " + die);
System.out.println("Do you want to roll dice again (Y/N)"); // used do-while loop to roll dice again
option = scan.next();
}
while(option.equals("y") || option.equals("Y") );
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.