Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-24-2007, 10:19 PM
Member
 
Join Date: Jul 2007
Posts: 46
adlb1300 is on a distinguished road
Problem calling another class
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:


Code:
/* * 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
Code:
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-24-2007, 10:25 PM
Member
 
Join Date: Jul 2007
Posts: 46
adlb1300 is on a distinguished road
Also forgot to include in previous post that I'm getting the following error message while trying to run from Netbeans:

symbol : constructor HistogramFreq()
location: class HistogramFreq
HistogramFreq freqCalc = new HistogramFreq();
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 10-25-2007, 06:10 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,146
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(); } } }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 10-25-2007, 03:05 PM
Member
 
Join Date: Jul 2007
Posts: 46
adlb1300 is on a distinguished road
Thanks for the help
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling displayable from a canvas class Snalk CLDC and MIDP 0 03-29-2008 12:58 AM
Calling a method in another class uncopywritable New To Java 8 01-14-2008 05:37 PM
Calling method from another class asahli New To Java 1 12-15-2007 07:24 PM
calling a java class from html Ed Advanced Java 1 07-08-2007 01:58 AM


All times are GMT +3. The time now is 09:39 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org