Answer to Question #272854 in Java | JSP | JSF for bbhhjj

Question #272854

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


1
Expert's answer
2021-11-28T18:41:26-0500
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;
            }
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS