1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

How to items from a different class to an ArrayList?

Discussion in 'Java' started by anzo31, Nov 14, 2010.

  1. anzo31

    anzo31 New Member

    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();
  2. anzo31

    anzo31 New Member

    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;
    Last edited by a moderator: Nov 14, 2010
  3. ihatec

    ihatec New Member

    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.

Share This Page