Histogram Programming Project
The purpose of this assignment is to enhance the Histogram program from the
Histogram Lab.
- 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,
Final Location |
|
Index |
-6 |
|
0 |
-4 |
|
1 |
... |
|
... |
0 |
|
3 |
... |
|
... |
- 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
Histogram
constructor
to make the call to the constructor more readable. Research the Histogram
class documentation to learn how to label the columns. You only
need to do this once, because the labels do not change as you run the simulation
or plot the different rows.
- Research the
Histogram
class documentation to learn how to plot a row with a row label that you
provide. Label each row with the final location represented by that row (-6,
-4, and so forth).
- Research the
Histogram
class
documentation to discover how to construct a histogram that plots the
contents of an array all at once. Note that you will no longer have to plot
the values explicitly; the new constructor takes care of all that.
- 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.