Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot find symbol -method itemsSold (int)

this segment is causing an error which says cannot find symbol – method itemsSold (int)

 int total = itemsSold(0);
 int max = itemsSold(0);
 int min = itemsSold(0);

I am assuming it is with those lines

public class Payroll
{
    private int[] itemsSold;
    
    public Payroll(int[] i)
    {
        itemsSold = i;
    }
    
    public static void ingWords (String [] w)
    {
    for(String str: w)
      {  
     if(str.substring(str.length()-3).equals("ing"))
          {
              System.out.println(str);
     }
    }
   }
   public double computeBonusThreshold()
   {
       int total = itemsSold(0);
       int max = itemsSold(0);
       int min = itemsSold(0);
       
       for(int i= 1; i < itemsSold.length; i++)
       {
           total += itemsSold[i];
           if(itemsSold[i] > max)
           {
               max = itemsSold[i];
            }
            if(itemsSold[i] < min)
            {
                min = itemsSold[i];
            }
        }
        return (double)(total-max-min)/(itemsSold.length-2);
}
}

and the tester class incase it is causing the problem somehow

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public class TestPayroll
{
    public static void main(String [] args)
    {
        String[] words = new String[] {"rolling", "hello", "watching", "goodbye", "hiking"};
        int[] sold = new int[] {48,50,37,62,38,70,55,37,64,60};
        
        
        Payroll.ingWords(words);
        
        Payroll company = new Payroll (sold);
        double threshold = company.computeBonusThreshold();
        System.out.println(threshold);
    }
    }

>Solution :

When you have parenthesis after itemsSold java thinks you are trying to call a method called itemsSold.

However your itemsSold is an array. To access array elements you need to use square brackets.

int total = itemsSold[0];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading