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. Provide in department class void addProjectWork(int pid, int wide, int hours)
This will add the hours to the worker of the given project. For 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
import java.util.ArrayList;
import java.util.Random;
public class Department {
private int id;
private String address;
private ArrayList<Project> projects;
private ArrayList<Worker> workers;
public Department(String address) {
id = new Random().nextInt(Integer.MAX_VALUE);
this.address = address;
projects = new ArrayList<>();
workers = new ArrayList<>();
}
public void addProjectWork(int pId,int wId,int hours){
for (Project project : projects) {
if (project.getId() == pId) {
project.addMemberHours(wId, hours);
break;
}
}
}
}
Comments
Leave a comment