Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * Here's another Switch example, this one from the book, but it's also a good example of the random number generator. Fig. 6 .
Here's another Switch example, this one
from the book, but it's also a good example
of the random number generator.
Fig. : RollDie.java
Roll a sixsided die a bunch of times.
import java.security.SecureRandom;
public class PartRandom
public static void mainString args
randomNumbers object will produce secure random numbers
SecureRandom randomNumbers new SecureRandom;
int frequency; count of s rolled
int frequency; count of s rolled
int frequency; count of s rolled
int frequency; count of s rolled
int frequency; count of s rolled
int frequency; count of s rolled
tally counts for rolls of a die
for int roll ; roll ; roll
int face randomNumbers.nextInt; number from to
use face value to determine which counter to increment
switch face
case :
frequency; increment the s counter
break;
case :
frequency; increment the s counter
break;
case :
frequency; increment the s counter
break;
case :
frequency; increment the s counter
break;
case :
frequency; increment the s counter
break;
case :
frequency; increment the s counter
break;
System.out.printlnFacetFrequency; output headers
System.out.printftdntdntdntdntdntdn
frequency frequency frequency frequency
frequency frequency;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started