Histogram Programming Project
The purpose of this assignment is to enhance the Histogram program from the
- Replace the seven variables representing the final location counters with
a single collection of seven values. You will need to initialize the counters
to 0, just as you did with the seven variables.
- Replace your series of if/else-if/else statements that increment
the seven variables with a single statement that increments the appropriate
element in the collection. To do this, you will need to develop an arithmetic
expression that, given the final location of the object, will give you the
correct index into the collection. For example,
- Replace the seven statements to plot the final locations with a single statement
in a loop.
- Provide a more descriptive title for the histogram, such as "Distribution
of final locations after six random moves." You may wish to create a variable
to hold the title and then pass that to the
to make the call to the constructor more readable.
- Add labels to the columns and rows of the histogram by placing a
text cell in the appropriate location. Label the columns at
consistent intervals (for example, every ten blocks) and
label each row with the final location represented
by that row (-6, -4, and so forth).
- Add space between your rows so that the histogram is easier to read.
- Import the
edu.kzoo.util.ValidatedInputReader class into your
Histogram project. Research the
class documentation for this class.
to learn how to call the
getInteger that takes 5 parameters: an initial
prompt string, a minimum value, a maximum
number value, a suggested value,
and a clarification prompt. You may
use the constant
Integer.MAX_VALUE to represent the
largest number that is acceptable. Once you have prompted the
user for the number of iterations, change your program so that it
uses this number to control the number of iterations that the
simulation runs. Then remove the
NUM_ITERATION constant. Test it with different
numbers of iterations, including zero and one or more negative
- Be sure that you have updated the class documentation at the top of the
file and that your program conforms to the style guidelines for this class.
The class documentation comments should describe the purpose and behavior
of your main class from a user's perspective. Focus on what the program
does, rather than how it does it. Include your name and the date as
well as the names of anyone from whom you received help. Following style and
documentation standards is an important step towards writing well-structured
and reusable programs.