Answer to Question #281527 in Java | JSP | JSF for ashooo

Question #281527

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 the Project class provide two abstract methods: getTeamSize(): that finds and returns the size of the team working on this project c and calculateCost(): that finds and returns cost of project. Provide a class ContractTeamProject that extends class Project

a. Provide an instance variable overheadCost (double). b. Override the calculateCost Method which calculates the project cost as a sum of all the member’ salaries and an additional surcharge at the rate of 11% of the salary amount plus the overheadCost

c. Override the toString to match the output .


1
Expert's answer
2021-12-20T12:37:15-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;


	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 ContractTeamProject extends Project {
	private double overheadCost;


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


	@Override
	public double calculateCost() {
		double salaryAmount = 0;
		for (int i = 0; i < members.size(); i++) {
			salaryAmount += members.get(i).getSalRate();
		}
		double surcharge = salaryAmount * 0.11 + overheadCost;
		return salaryAmount + surcharge;
	}


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


		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