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 main(String[] args){
boolean again;
Scanner scan = new Scanner(System.in);
Random rand = new Random();
//1. Declare some variables:
//-6 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
//2. Set up an outer do-while loop, which ends when
// the boolean variable "again" is false
//3. A do-while that asks how many dice the user wants
//(constrain the user to 1-3) and assigns the
// resulting value to the variable "dice".
//4. A do-while that asks how many sides each die should have
//(constrain the user to 2-9) and assigns the resulting
// value to the variable "sides".
//5. A do-while that asks how many times to roll the die
//(constrain the user to 1000-100 million) and assigns the
// resulting value to the variable "rolls".
System.out.println();
//6. Assign values to minIndex and maxIndex,
// based on the number of dice and how
// many sides each die has.
//7. Initialize counts to a new int array
// with a size of maxIndex plus 1
//8. Repeatedly roll the dice
//--Set "dieSum" back to zero
//--For each die, generate a random integer
// between 1 and the number of sides, and
// add the resulting value to "dieSum"
//--Increment the element in the counts array
//9. Call the Histogram constructor with the variables counts,
// minIndex, maxIndex, MAX_LENGTH; 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.print("Continue?(\"true\" for yes and \"false\" for no): ");
again = scan.nextBoolean();
System.out.println('
');
// end of the do-while loop indicated in step 2.(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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!