Skip to main content

How to draw a histogram

1 reply [Last post]
tonyyou1988
Offline
Joined: 2008-10-30

In this part of the lab, we will implement a class Histogram that creates a histogram from data passed as arguments on the command line. A histogram gives a visual representation of the frequency distribution of a set of values. Your program should take an arbitrary number of integers from the command line that all have values between 1 and 100 inclusive. The program will then output a chart that prints an asterisk for each value entered that falls within a specified range. The total number of asterisks printed will be the same as the total number of values entered at the command line.

For example, the following command line arguments, passed to Histogram:

java Histogram 1 20 72 45 30 22 32 44 5 12 7 23 50 26 55 21 79 99 30 3 92 81 2

Should produce the following output:

1 - 10 | *****
11 - 20 | **
21 - 30 | ******
31 - 40 | *
41 - 50 | ***
51 - 60 | *
61 - 70 |
71 - 80 | **
81 - 90 | *
91 - 100 | **

There were 5 values entered that fell between 1 and 10 (1, 5, 7, 3, 2), 2 values that fell between 11 and 20 (20, 12), 6 that fell between 21 and 30 (30, 22, 23, 26, 21, 30) etc. Note that there are 5 asterisks on the first line (1 - 10), 2 asterisks on the second line (11 - 20) etc.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jhipp117
Offline
Joined: 2008-08-24

tonyyou1988, is your post ironic, or do you have a question about histograms?

JHipp