java rolling dice program
Subject
Programming
Question Description
Histogram.java
HistogramCLI.java
In this project, we will write a program that simulates the rolling of dice, performs many rolls, and determines the frequency for each possible sum of the dice. We will create a kind of bar graph called a histogram and display it in two forms - one horizontal and one vertical. This project will require you to write several loops that process the integer variables in an array - as well as how to use a method (even if you do not understand it's inner workings).
You can find an initial version of the Histogram.java and HistogramCLI.java source files in project2.zip. As always, download and unzip this file on your removable media (or your own computer). You may find it helpful to create/save a Dr Java project file in the project2 directory.
How this program will work is as follows:
Prompts user for how many dice to roll (1 to 3).
Prompts user for how many sides each die should have (2 to 9).
Asks user how many times to roll the dice (1000 to 2 billion).
Rolls the dice that number of times.
Creates a Histogram object and determine how tall each bar should be.
Calls the Histogram object's methods for drawing the histogram, both horizontal and vertical. (Check out the sample outputbelow, to see how this might look.)
For this project, you will be working in both classes, writing the code that enables the program to work. The individual steps are in the comments in the files, but I'll also go over them briefly here:
In HistogramCLI.java...
Declare your variables. (Details in code comments)
Set up one do-while loop, that will encompass three others, along with the majority of the code in the main method. It will allow repeated execution of the rest of the program, until the user indicates to stop. That outermost do-while loop will encompass steps 3-10 below.
Prompt the user for how many how many dice to roll (1 to 3), but only allow a number within the specified range.