Answer to Question #281526 in Java | JSP | JSF for asmf

Question #281526

You are required to write builds a record book for Projects being conducted at a department. A Project has an id, description, array list of members and start and end dates. In project class provide two abstracts methods: getTeamSize(): that finds and returns the size of the team working on this project c and calculateCost(): that finds cost of the project. Provide a class HourlyTeamProject that extends Project, Add an instance variable hourCost (double) that represents the utility bills cost charged per hour worked on this project by each team member. Provide a method getTotalHours() that returns the total number of hours worked by each member on this project. Override the calculateProjectCost method which calculates the total cost by following relation

     Total cost = total salary of all members + hoursCost * total hours on this project 


1
Expert's answer
2021-12-20T12:37:18-0500


import java.util.Scanner;
import java.util.ArrayList;


class Worker {
	private double salRate;


	/**
	 * @return the salRate
	 */
	public double getSalRate() {
		return salRate;
	}


	/**
	 * @param salRate the salRate to set
	 */
	public void setSalRate(double salRate) {
		this.salRate = salRate;
	}


}


abstract class Project {
	private int id;
	private String description;
	protected ArrayList<Worker> members;
	private String startDate;
	private String endDate;
	protected double hours;


	public Project() {


	}


	public abstract int getTeamSize();


	public abstract double calculateCost();


	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}


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


	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}


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


	/**
	 * @return the startDate
	 */
	public String getStartDate() {
		return startDate;
	}


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


	/**
	 * @return the endDate
	 */
	public String getEndDate() {
		return endDate;
	}


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


class HourlyTeamProject extends Project {
	private double hourCost;


	@Override
	public int getTeamSize() {
		return members.size();
	}


	public double getTotalHours() {
		return hourCost;
	}


	@Override
	public double calculateCost() {
		double salaryAmount = 0;
		for (int i = 0; i < members.size(); i++) {
			salaryAmount += members.get(i).getSalRate();
		}
		// Total cost = total salary of all members + hoursCost * total hours on this
		// project
		return salaryAmount + hourCost * hours;
	}


	@Override
	public String toString() {
		String output = "Project ID: " + getId() + "\nProject description: " + getDescription()
				+ "\nProject Start Date: " + getStartDate() + "\nProject End Date: " + getEndDate() + "\nHour cost: "
				+ hourCost;


		return output;
	}


}


public class App {


	/**
	 * The start point of the program
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {


		Scanner keyBoard = new Scanner(System.in);


		keyBoard.close();
	}
}

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