Answer to Question #272811 in Java | JSP | JSF for Tara

Question #272811

Build a class Project with id(int) , desc (String), duration (int) , budget (double) and members (ArrayList of Workers). Provide a parameterized constructor Project (int id, String desc, double budget). The member array will be initialized as empty array and the initial duration of the project will be 0 b. Provide setters for description and budget and getters for all except members list

 Provide a method getTotalCost() that calculates the total cost of the project by summing the budget and the salary of each member of the project. The salary of each member can be found by calculating an appropriate method of the Worker class .


1
Expert's answer
2021-11-30T18:19:49-0500
class Project {
	// id(int), desc (String), duration (int) , budget (double) and members
	// (ArrayList of Workers).
	private int id;
	private String desc;
	private int duration;
	private double budget;
	private ArrayList<Worker> members;


	/**
	 * parameterized constructor Project (int id, String desc, double budget). The
	 * member array will be initialized as empty array and initial duration of
	 * project will be 0.
	 * 
	 * @param id
	 * @param desc
	 * @param budget
	 */
	public Project(int id, String desc, double budget) {
		this.id = id;
		this.desc = desc;
		this.budget = budget;
		this.members = new ArrayList<Worker>();
		this.duration = 0;
	}





	




	/***
	 * method getTotalCost() to calculate total cost of project by summing budget
	 * and salary of each member of project.
	 * 
	 * @return
	 */
	public double getTotalCost() {
		double totalCost = 0;
		for (Worker worker : members) {
			totalCost += worker.getCurrentSalary();
		}
		return totalCost;
	}


	
	// Provide setters for description & budget & getters for all except members
	// list.


	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}


	/**
	 * @param desc the desc to set
	 */
	public void setDesc(String desc) {
		this.desc = desc;
	}


	/**
	 * @param duration the duration to set
	 */
	private void setDuration(int duration) {
		this.duration = duration;
	}


	/**
	 * @param budget the budget to set
	 */
	private void setBudget(double budget) {
		this.budget = budget;
	}


	public int getId() {
		return this.id;
	}


}

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