Question: import java.util.Random; import java.util.Scanner; public class HistogramCLI { public static void main ( String [ ] args ) { boolean again; Scanner scan = new
import java.util.Random;
import java.util.Scanner;
public class HistogramCLI
public static void mainString args
boolean again;
Scanner scan new ScannerSystemin;
Random rand new Random;
Declare some variables:
int variables: dice, sides, rolls, dieSum,
minIndex, maxIndex. Initialize
all these to zero
A Histogram reference variable by the name "hist"
just declare do not initialize yet!
An int array variable by the name "counts"
just declare do not initialize yet!
NOTE: The remainder of the code will involve several
nested loops. Please pay attention to the
indentation of my comments, to help yourself
keep track of what is nested where
Set up an outer dowhile loop, which ends when
the boolean variable "again" is false
A dowhile that asks how many dice the user wants
constrain the user to and assigns the
resulting value to the variable "dice".
A dowhile that asks how many sides each die should have
constrain the user to and assigns the resulting
value to the variable "sides".
A dowhile that asks how many times to roll the die
constrain the user to million and assigns the
resulting value to the variable "rolls".
System.out.println;
Assign values to minIndex and maxIndex,
based on the number of dice and how
many sides each die has.
Initialize counts to a new int array
with a size of maxIndex plus
Repeatedly roll the dice
Set "dieSum" back to zero
For each die, generate a random integer
between and the number of sides, and
add the resulting value to "dieSum"
Increment the element in the counts array
Call the Histogram constructor with the variables counts,
minIndex, maxIndex, MAXLENGTH; and assign the object to hist.
Then, call the drawHor and drawVer methods, with lines
skipped in between for neater output.
Sees if user wants to go again.
System.out.printContinuetrue for yes and false for no: ;
again scan.nextBoolean;
System.out.println
;
end of the dowhile loop indicated in step The condition is the
boolean variable "again"
Java code in all the steps
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
