Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have six classes 1.abstract Employee 2. HourlyEmployee 3. SalaryEmployee 4. Co

ID: 3627301 • Letter: I

Question

I have six classes
1.abstract Employee
2. HourlyEmployee
3. SalaryEmployee
4. Commission Employee
5. Employee Manager
6. EmployeeDriver

So the Driver class is suppose to ask if the user wants to add an employee. So I have an option that says Hourly.

In the Manager class I have the function :

public void addHourly(String fn, String ln, char m, char g, int empNum, boolean ft, double wage, double hoursWorked)
{
employees[currentEmployees] = new HourlyEmployee(fn,ln,m,g,empNum,ft,wage,hoursWorked);

}

In the driver class I create an object of employee and ask the user for information which is passed along to the addHourlyEmployee method in the Manager class, which calls the constructor in HourlyEmployee Class.

However I enter all the user information in and then I get:


Exception in thread "main" java.lang.NullPointerException
at EmployeeManager.addHourly(EmployeeManager.java:18)
at EmployeeDriver.main(EmployeeDriver.java:61)

If I remove
employees[currentEmployees] = new HourlyEmployee(fn,ln,m,g,empNum,ft,wage,hoursWorked);

from the Manager class my loop in the Driver class complies. Am I creating this correctly??

Explanation / Answer

1 . before calling EmployeeManager.addHourly() method from Driver class , make sure u have instantiated EmployeeManager object ie Manager EmployeeManager = new Manager(); 2. i doubt the problem may be with employees array in manager class , is it properly intialized . If the employees array is properly initialized make sure it of HourlyEmployee type or any of the HourlyEmployee 's super classes . other cases may be * Calling the instance method of a null object. * Accessing or modifying the field of a null object. hope this helps , or else message me ur code . i ll look thru it :) please rate