
/* This file defines a "histogram" program.  The user is asked to
   enter some numbers.  The numbers are stored in an array.
   Then the data in the array are displayed in the form of a
   histogram. (For each number in the array, the histogram
   shows a line of stars.  The number of stars in the i-th line
   is equal to the number in the i-th spot in the array.)

   NOTE:  Your assignemnt is to complete the missing parts of
          of the program.  You can use the stars() subroutine,
          given below, to output each line of stars.
*/
   

public class Histogram {

   static Console console = new Console();  // console for input/output

   public static void main(String[] args) {

      int numberOfLines;  // The number of lines in the histogram.
                          // This is also, therefore, the size of the array.
      
      int[] data;  // The array of data, containing numbers entered by the user.
      
      console.putln("This program will display a histogram based on data");
      console.putln("you enter.  You will be asked to enter the numbers");
      console.putln("that specify how many *'s there are in each row of");
      console.putln("the histogram.  The numbers must be between 0 and 50.");
      console.putln("");


      // Find out how many numbers the user wants to enter.
      // This number is restricted to be in the range 1 to 25.

      do {
          console.put("How many numbers do you want to enter? ");
          numberOfLines = console.getlnInt();
          if (numberOfLines < 1 || numberOfLines > 25)
             console.putln("Please specify a number between 1 and 25.");
      } while (numberOfLines < 1 || numberOfLines > 25);


      // Create an array to hold the user's numbers.  The size of the
      // array is given by the number of numbers the user wants to enter.

      data = new int[numberOfLines];

      // Use a for loop to read the user's numbers, one at a time, and
      // store them in the array:

              // ************ YOU HAVE TO DO THIS ***********


      console.putln();
      console.putln("Here's a histogram of your data:");
      console.putln();
      console.putln("          10        20        30        40        50");
      console.putln("|---------|---------|---------|---------|---------|-----");


      // Output the histogram, using a for loop.  Call the "stars()"
      // once for each number in the array:


              // ************ YOU HAVE TO DO THIS ***********


      console.putln("|---------|---------|---------|---------|---------|-----");

      console.close();

   }  // end main();

   static void stars(int starCount) {
        // Outputs a line of *'s, where starCount gives the
        // number of *'s on the line.  There is a carriage
        // return at the end of the line.
      for (int i = 0;  i < starCount;  i++) {
         console.put('*');
      }
      console.putln();
   }


}  // end of class Histogram