Skip to content
Snippets Groups Projects
Staff.java 1.79 KiB
Newer Older
eyan_'s avatar
eyan_ committed
package com.example.schedulerapp;

import java.util.ArrayList;
import java.util.List;

eyan_'s avatar
eyan_ committed
public class Staff {
    /*
    Test to see if this works with 'final' key word.
     */
    private final List<Employee> allStaff = new ArrayList<>();

    public void addEmployee(String name, String position, float wage, String number, boolean manager, Shift[] availability) {
        int ID = 0;
        if (allStaff.size() > 0) {
            ID = allStaff.get(allStaff.size() - 1).getID() + 1;
        }
        Employee newEmployee = new Employee(name, position, wage, number, manager, availability, ID);
        this.allStaff.add(newEmployee);
    }

    public void removeEmployee(int ID) {
        for (Employee employee: allStaff) {
            if (employee.getID() == ID) {
                allStaff.remove(employee);
                break;
            }
        }
    }

    /*
    Not finished. Names are not unique. Although, getting employees by name is convenient.
     */
    public void removeEmployee(String name) {
        for (Employee employee: allStaff) {
            if (employee.getName().equals(name)) {
                allStaff.remove(employee);
                break;
            }
        }
    }

    public Employee getEmployee(int ID) {
        for (Employee employee: allStaff) {
            if (employee.getID() == ID) {
                return employee;
            }
        }
        return null;
    }

    /*
    Not finished. Names are not unique. Although, getting employees by name is convenient.
     */
    public Employee getEmployee(String name) {
        for (Employee employee: allStaff) {
            if (employee.getName().equals(name)) {
                return employee;
            }
        }
        return null;
    }

    public List<Employee> getAllStaff() {
        return allStaff;
    }
eyan_'s avatar
eyan_ committed
}