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.
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();
}
}
Comments
Leave a comment