Issue
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
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];
Answered By - Ariel Katz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.