I'm trying to create a program that will prompt the user for 10 values between 0 and 99. Once I have the values I want to create a little output bar chart using the asterik sign to show how many of the values fell into each category of 10, ie 0-9, 10-19, etc.. I'm able to prompt the user for the values and store them into an array however I'm having trouble calling to the class I developed for determining the frequency and outputting the chart. Any advice would be helpful. Also if I'm making it harder than I have to let me know that as well. Here is the code I have:
/*
* Histogram.java
*
* Created on October 24, 2007, 3:52 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author Bill
*/
import java.io.*;
import javax.swing.*;
public class Histogram {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// creates
int inputtedValue[] = new int[ 10 ]; // array to hold inputted data
for( int inputCounter = 0; inputCounter < inputtedValue.length; inputCounter++ ) {
String input = JOptionPane.showInputDialog
("Please enter a number between 0 and 99\n" +
"Stop entering values at any time by entering -1.\n");
int numberProvided = Integer.parseInt(input);
inputtedValue[ inputCounter ] = numberProvided;
}
HistogramFreq freqCalc = new HistogramFreq();
freqCalc.processValues();
} // end main
} // end class Histogram
public class HistogramFreq
{
private int valuesProvided[];
public HistogramFreq(int inputtedValue[])
{
valuesProvided = inputtedValue;
}
public void processValues()
{
determineFrequency();
}
public void determineFrequency()
{
int frequency[] = new int [10];
for( int valueEntered : valuesProvided)
++frequency[valueEntered/10];
for(int count = 0; count < frequency.length; count++)
{
System.out.printf("%02d-%02d: ", count * 10, count * 10 + 9);
for(int stars = 0; stars < frequency[count]; stars++)
System.out.print("*");
System.out.println();
}
} // end method determineFrequency()
} // end class HistogramFreq