View Single Post
  #3 (permalink)  
Old 10-25-2007, 07:10 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
About the error:
Code:
// You are using a no-argument constructor. HistogramFreq freqCalc = new HistogramFreq(); ... // The HistorgamFreq class does not have a no-args // constructor, only a one-argument constructor. public HistogramFreq(int[] inputtedValue)
The rule is that if you do not specify a constructor for a class the vm (virtual machine) gives you one (a no-args/default constructor) for free. If you do specify a constructor with one or more arguments the vm does not provide a default no-args constructor. So if you want a no-args constructor in this case you must provide it for your class.
Code:
import javax.swing.JOptionPane; public class H { public static void main(String[] args) { 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(inputtedValue); freqCalc.processValues(); } } class HistogramFreq { private int[] valuesProvided; public HistogramFreq(int[] inputtedValue) { valuesProvided = inputtedValue; } public void processValues() { determineFrequency(); } public void determineFrequency() { for(int j = 0; j < valuesProvided.length; j++) { System.out.printf("%02d-%02d: ", j * 10, j * 10 + 9); for(int k = 0; k < valuesProvided[j]/10; k++) System.out.print("*"); System.out.println(); } } }
Reply With Quote