Um, there's a whole bunch of problems in your code, not just the "static" one.
You've created the class ProductionEmployee inside Employee. Therefore, it does not extend Employee but is a component of it. The two employees below are just employees regardless of the fact that you have named one productionEmployee.Employee employee1 = new Employee ( ); // Declares Employee object.
Employee productionEmployee = new Employee ( ); // ProductionEmployee
Instead, you should have an Employee class with no reference to ProductionEmployee and a separate ProductionEmployee class that extends Employee.public class ProductionEmployee
extends Employee
{
// Your addional ProdEmp code goes here.
// The basic Employee methods and fields are included automatically
// by the "extends" clause above.
}
The declarations above then become:Employee employee1 = new Employee ( ); // Declares Employee object.
ProductionEmployee productionEmployee = new ProductionEmployee ( ); // ProductionEmployee
You now have two employees, one of whom is a production employee.
As to the "static" problem: A static method is available to all Employees (in this case). A non-static method is only available to individually named employees (such as employee1 and productionEmployee above. In the line you highlighted you are calling the method getYearOfHire
but you are not identifying whose year of hire you want. One solution would be to rewrite the method as follows:/**
* Add a dollar to the given pay rate for each year of service.
* @param yearOfHire The year in which the employee was hired.
* @param hourlyPayRate The employee's pay rate (in dollars).
* @return The employee's modified pay rate.
*/
public static int calcPayRate(int yearOfHire, int hourlyPayRate)
{
int yearsHired = yearOfHire - 2009;
int newPayRate = hourlyPayRate;
for ( int index = 0; index <= yearsHired; index ++)
{
newPayRate++;
}
return newPayRate;
}
You would then need to modify the rest of you code to use his modified method appropriately.