Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   How to items from a different class to an ArrayList? (http://www.go4expert.com/forums/items-class-arraylist-t23865/)

anzo31 14Nov2010 08:54

How to items from a different class to an ArrayList?
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();

anzo31 14Nov2010 09:16

Re: How to items from a different class to an ArrayList?

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;

            if paycode = 2;



ihatec 17Nov2010 04:12

Re: How to items from a different class to an ArrayList?
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:

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.

All times are GMT +5.5. The time now is 05:52.