Programming Assignment 9

This assignment is a modification of Programming Projects 6.4 and 6.5 on page 375 of our textbook. Instead of having your program "read in an arbitrary number of integers that are in the range from 1 to 100 inclusive", your program should randomly generate the integers from 1 to 100 and your program should prompt the user for the number of random integers to generate. Also, instead of creating a histogram with 10 bars, create one with 25 bars, so the bars represent the ranges 1-4, 5-8, 9-12, etc. You do not need to label the histogram bars on the left edge, as in the figure on page 375. Notice that if a user asks for a very large number of randomly generated integers, some histogram bars may be wider than the screen. So you should scale the histogram bars so that the longest bar fits on one row of the screen. Do not do as in Project 6.5, where every asterisk always represents five values. You should compute a minimum scaling factor for the histogram, so that each asterisk represents only enough values so that the longest histogram bar fits in one row.

For generating the random numbers, use the Random class from the java.util package.

Your program should continue to prompt the user for a sample size, generate the random data, and draw the histogram until the user inputs a sample size of 0.

This assignment can be done with just one file. You can put all of your code into the main method or in static helper methods. You can download this CS123Ass9.class class file and run it to see how this program is supposed to work.

This assignment is due Wednesday, November 12.


Return to the main homework page.
Return to the main Java page.
Return to the CS 123 home page.


compliments and criticisms