I want to Create an Employees class. It will contain 1 arraylist which holds Payable objects (Manager, HourlyWorker, all implement Payable). It will have a method to addEmployee, calculateWeeklyTotal, retrieve number of managers, hourly workers. and the toString method will print out the employee number and weekly pay for all employees. It will have a generateWeeklyPayReport method that returns a string with the entire report. Also the class Manager contain variable to hold paycode1, the salary and the ID and the class HourlyWorker contain variable to hold paycode2, hourly salary, and hours worked (for this class, employeees recieve fixed hourly wage for up to the first 40 hours they work and "time-and-a-half," i.e., 1.5 times their hourly wage, for overtime hours worked), payable interface has the methode public double calculateWeeklyPay();
Code: public class Employees { private payable Manager; private payable HourlyWorker; private ArrayList<String>EmployeesBorad; private int paycode; public Employees() { EmployeesBorad= new ArrayList<String>(); paycode = 0; Manager = null; HourlyWorker = null; } public void addEmployees (String Manager, String HourlyWorker) { if paycode = 1; EmployeesBorad.add(Manager); if paycode = 2; EmployeesBorad.add(HourlyWorker); } ...... }
If I understood your problem correctly, I would recommend slightly different solution. I don't know what is your level, but I assume you've heard about polymorphism. I haven't read the full code, but I will do it in such a way: 1. Employee class would superclass(can be abstract) 2. Other classes will be subclasses of Employee class 3. Use polymorphism for example like that: Code: ArrayList<Employee> list = new ArrayList<Employee>(); list.add(new Manager()); Your description looks strange for me. Because you want to have objects of Payable, but as I understood it is an interface.