I am working on an employee inheritance problem.
Employee is the top class,
Labourer extends Employee
Foreman extends Labourer
Manager extends Employee
Executive extend Manager
I am working on the statistics part of the problem and have used the following code to get the total wages of all labourers.
public static void labStats(Employees [] emps, int size)
{
int x,noL=0,total=0;
for ( x= 0 ; x < size; x ++)
{
if ( emps[x] instanceof Labourers)
{
noL++;
total = total + ( (Labourers) emps[x] ).getWages();
}
}
p("\n\t\t\t" + noL + " Labourers");
p("\n\t\t\tThe total of wages paid to labourers is ?" + total);
p("\n\t\t\tThe average paid to each labourer is ?" + total/noL);
p("\n\n");
}
When I do this I am also getting the wages of the foremen added in on the count, now I know that they are also a labourer but as regards to the compiling of statistics they are a foreman.
Is there any way I can count only those who are labourers?