Tuesday, November 1, 2011

Lab 7 - CountingDigits.java

You are to complete exercise 6.7
(6th ed, p205; 7th ed, p222; 8th ed, p228).

The class name must be CountingDigits. You must write it as a command line application.

This assignment requires that you generate 100 pseudo-random numbers, between 0 and 9, inclusive. You need to use an array to keep track of how many times each digit is generated. The most efficient way to do this is to create one ten-integer array, named counts, and to increment the contents of the appropriate array location each time its value is randomly generated. That is, each time your code generates a 0, you increment the contents of counts[0]; each time your code generates a 1, you increment the contents of counts[1]; and so on.

You must create the histogram in a method. This is its header:

   public static int[] generateHistogram()

You must also display your results using a method. This is its header:

   public static void printIndexAndValue(
      int[] array)


Sample Output
Here is a screenshot of my code running.

CountingDigits output

Refer to the deliverables post for comment formatting and required program identification information.

Due Date:
Monday, November 7th, 8:00am