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

Question #272690

The workers work for some hours on each assigned projects which adds to the total number of hours and the salary is calculated according to the salary rate of each worker. The project duration is the total number of hours worked by each member of the project. Each project has some budget but the total cost of the project is the sum of budget and the salary of each project member. Follow these steps to build your application. 1. 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 c. Provide a method addWorker(int id, String name, double salRate) that creates an instance of Worker and adds it to the workers list d.


1
Expert's answer
2021-11-28T11:44:58-0500
import java.util.ArrayList; 
public class Main
{
	public static void main(String[] args) {
		
	}
}


class Department{
    private int id;
    private String address;
    private ArrayList <String> projects;
    private ArrayList <Worker> workers;
    
    public Department (String address){
        this.address=address;
        id=0;
        projects=new ArrayList <String>();
        workers= new ArrayList <Worker>();
    }
    
    public int getId(){
        return id;
    }
    
    public String getAddress(){
        return address;
    }
    public void setAddress(String address){
        this.address=address;
    }
    public void addWorker(int id, String name, double salRate){
        Worker w=new Worker(id,name,salRate);
        workers.add(w);
        
    }
}


class Worker{
    private int id;
    private String name;
    private int hoursWorked;
    private double salRate;
    
    public Worker(int id, String name, double salRate){
        this.id=id;
        this.name=name;
        this.salRate=salRate;
        hoursWorked=0;
    }
    public int getId(){
        return id;
    }
    public String getName(){
        return name;
    }
    public int getHoursWorked(){
        return hoursWorked;
    }
    public double getSalRate(){
        return salRate;
    }
    public void setSalRate(double salRate){
        this.salRate=salRate;
    }
    public void addHours(int h){
        hoursWorked=hoursWorked+h;
    }
    public double getCurrentSalary(){
        return (hoursWorked*salRate);
    }
    public String toString(){
        return "Current Salary = "+getCurrentSalary();
    }
}

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