Answer to Question #272691 in Java | JSP | JSF for bikki

Question #272691

Provide a method addProject(int id, String description, double budget) that creates a project and adds it to the project list e. Provide method addWorkerToProject(int projId, int wId) that searches for the project with projId from the projects list and worker with wId from the members lists and then adds the member to the project (you will call appropriate method of the project class that will add the member to the project. See blow the project class for details. f. Provide a method getProjectCost(int pid) which searches for the project with the given id from the projects list and then returns its total cost (you can call a method from the project class to get the total cost… see the project class for details) g. 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) h.


1
Expert's answer
2021-11-30T18:19:53-0500
import java.util.ArrayList;

public class Main {
    private ArrayList<Project> projects;
    private ArrayList<Worker> workers;

    public void addProject(int id, String description, double budget) {
        projects.add(new Project(id, description, budget));
    }

      public void addWorkerToProject(int projId, int wId) {
        Worker worker = null;
        for (Worker workerL : workers) {
            if (workerL.getId() == wId) {
                worker = workerL;
                break;
            }
        }
        if (worker != null) {
            for (Project projectL : projects) {
                if (projectL.getId() == projId) {
                    project.addMember(worker);
                    break;
                }
            }
        }
    }

    public double getProjectCost(int pId) {
        for (Project project : projects) {
            if (project.getId() == pId) {
                return project.getTotalCost();
            }
        }
        return 0;
    }

    public double getDepartmentTotalBudget() {
        double total = 0;
        for (Project project : projects) {
            if (project.getId() == projId) {
                total += project.getTotalCost();
            }
        }
        return total;
    }
}

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