Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * <p>Title: Histogram</p>
- *
- * <p>Description: Histogram Drawing Class</p>
- *
- * <p>Copyright: Copyright (c) 2009</p>
- *
- * <p>Company: UMB</p>
- *
- * @author Bob Wilson
- * @version 1.0
- */
- public class Histogram
- {
- private int [] values;
- private int minIndex;
- private int maxIndex;
- private int maxLength;
- /** constructor for histogram drawing class
- * @param values: the array of integer values to draw
- * @param minIndex: the lowest index in the array for the range to draw
- * @param maxIndex: the highest index in the array for the range to draw
- * @param maxLength: the length of line to draw for the largest value
- */
- public Histogram(int [] values, int minIndex, int maxIndex, int maxLength)
- {
- // initialize the values of the instance variables from the constructor parameters
- this.values = new int [maxIndex + 1]; // allocate memory for a copy of the values array
- this.minIndex = minIndex;
- this.maxIndex = maxIndex;
- this.maxLength = maxLength;
- // step 6:
- // find largest number in values array for scaling length of bars
- int maxValue=0;
- for (int i=0; i <= values.length-1; i++){
- if (values[i]>maxValue)
- maxValue=values[i];
- }
- // step 7:
- // copy data from values array to this.values array while scaling to maximum length of bars
- for(int i=0; i<=values.length-1; i++){
- this.values[i] = (int)((double)(values[i]*maxLength)/maxValue);
- }
- }
- /** draw a horizontal bar graph
- */
- public void drawHor()
- {
- // step 8:
- // draw horizontal bar graph (one line per roll value)
- for (int i=2; i <= maxIndex; i++){
- System.out.print ("Value " + i + ": ");
- for (int z=0; z <= values.length-1; z++){
- if (values[i] == z)
- System.out.println(" " + values[i]);
- else
- System.out.print("*");
- }
- }
- }
- /** draw a vertical bar graph
- */
- public void drawVer()
- {
- // step 9:
- // draw vertical bar graph (one column per roll value)
- }
- }/*201040*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement