Answer to Question #272810 in Java | JSP | JSF for bhhu

Question #272810

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



1
Expert's answer
2021-11-29T12:29:31-0500


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;
	}


}

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