#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    1
    Rep Power
    0

    Unhappy Exception handling program error


    hey guys
    please help
    when i run the code i get : error cannot find symbol
    for outputData(actualVotes, voteTalley);

    i know that im calling it in the main method and that i need to add it to a class some how but i dont know how can somebody please show me i will paste code below

    thanks so much

    <code>


    import java.util.*;


    public class RateJava {

    public static void main (String [] args)

    {

    int [] voteTalley = {0,1,2,3,4,5,6,7,8,9,10};

    int [] actualVotes = new int [11];



    inputData(actualVotes);

    outputData(actualVotes, voteTalley);



    }

    public static void inputData (int[]actualVotes)


    {

    Scanner myKeyboard = new Scanner (System.in);

    while(true)

    {

    int index;

    System.out.print("Please enter your votes (-1 to exit): ");



    try

    {

    index = myKeyboard.nextInt();

    }



    catch(InputMismatchException e)

    {

    System.out.println("This is an invalid number");

    myKeyboard.nextLine();

    continue;

    }



    if(index == -1)

    return;

    if (index >= 0 && index < actualVotes.length)

    actualVotes[index]++;

    else

    System.out.println("Invalid number");



    }
    }
    }

    <code>
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,740
    Rep Power
    1959
    Please put your code in code tags to keep proper code format/indentation.

    you will have to create the function, similar to what you did with when you created the inputData function.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    3
    Rep Power
    0
    Here is his code in a more readable format.

    Code:
    import java.util.*;
    
    
    public class RateJava {
    
    	public static void main (String [] args)
    
    	{
    
    		int [] voteTalley = {0,1,2,3,4,5,6,7,8,9,10};
    		int [] actualVotes = new int [11];
    
    		inputData(actualVotes);
    		outputData(actualVotes, voteTalley);
    
    	}
    
    	public static void inputData (int[]actualVotes)
    	{
    		Scanner myKeyboard = new Scanner (System.in);
    
    		while(true) 
    		{
    			int index;
    			System.out.print("Please enter your votes (-1 to exit): ");
    			try
    			{
    				index = myKeyboard.nextInt();
    			}
    			catch(InputMismatchException e)
    			{
    				System.out.println("This is an invalid number");
    				myKeyboard.nextLine();
    				continue;
    			}
    
    			if(index == -1)
    				return;
    
    			if (index >= 0 && index < actualVotes.length)
    				actualVotes[index]++;
    
    			else
    				System.out.println("Invalid number");
    
    
    
    		}
    	}
    }
    The problem with this code, as MrFujin stated, is that you are calling a function that does not exist.

    This line works fine because you have a method called inputData that accepts an array as an argument.

    inputData(actualVotes);

    The line outputData(actualVotes, voteTalley); is a compilation error because this is an undefined method.

    I'm not 100% sure what the purpose is of this code, but I think your outputData method will look something like this...

    Code:
    	public static void outputData(int[] a, int[] b)
    	{
    		for (int i = 0; i < a.length; i++)
    		{
    			System.out.println("There were "+a[i]+" votes rating Java a "+b[i]+".");
    		}
    	}

IMN logo majestic logo threadwatch logo seochat tools logo