Build a class Department having id (int), address (String) and projects (array list of projects) and workers (array list of workers) a. Provide parameterized constructor Department (String address) which initialized id randomly and array lists as empty array lists b. Provide getters for id and address and setter for address only.
Provide a method getDepartmentTotalBudget() that calculates the total cost of each project of the department and adds it up to get the total budget (You will call appropriate method of the Project instances to get the project costs). Please provide in department class void addProjectWork(int pid, int wide, int hours) This will add the hours to the worker of the given project. In this you will need to call the appropriate method of the project class i.e addMemberHours which adds the hours for the specified member as well as add to duration of the project
class Department {
private int id;
private String address;
private ArrayList<Project> projects;
private ArrayList<Worker> workers;
/**
* parameterized constructor Department (String address) which initialized id
* randomly & array lists as empty array lists.
*
* @param address
*/
public Department(String address) {
this.id = (int) (Math.random() * 100);
this.address = address;
this.projects = new ArrayList<Project>();
this.workers = new ArrayList<Worker>();
}
public double getDepartmentTotalBudget() {
double totalCost = 0;
for (Project project : projects) {
totalCost += project.getTotalCost();
}
return totalCost;
}
public void addProjectWork(int pid, int wide, int hours) {
for (Project project : projects) {
if(project.getId()==pid) {
project.getMember(wide).addHours(hours);
}
}
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @return the address
*/
public String getAddress() {
return address;
}
/**
* @param address the address to set
*/
public void setAddress(String address) {
this.address = address;
}
}
Comments
Leave a comment