Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write this code in Java perferably for Swift: Consider the Company class

ID: 3883744 • Letter: P

Question

Please write this code in Java perferably for Swift:

Consider the Company class and the program output given. Now, design a class hierarchy that implements company employee’s salary calculation. A company has two types of employees: hourly paid employees and monthly salary based employees. Every employee has a name, salary and tax rate.

In addition, hourly paid employee has two attributes: hours worked and the hourly rate. The monthly paid employee has one attribute, annual salary. Both classes have constructor methods that take all attributes and a method to calculate monthly salary.

Finally both classes should have the toString method that returns name, monthly salary, and the tax paid

ArrayList empList= new ArrayList(); monthlyPaidEmp mpE1 = new monthlyPaidEmp("John William" , 55675.00);

monthlyPaidEmp mpE2 = new monthlyPaidEmp("Nancy William" , 65675.00); hourlyPaidEmp hpE1 = new hourlyPaidEmp("Samira Monid", 7.50, 35);

}

}

} }

System.out.println(empList.get(i));

a) Draw the UML class diagram that represents the above class hierarchy b) Implement the classes in your UML diagram above

Explanation / Answer

Please find the required solution: import java.util.ArrayList; import java.util.List; abstract class Employee { private String name; private double salary; final double tax_rate = 5; public Employee( String name ) { this.name = name; } public String getName() { return name; } public void setName( String name ) { this.name = name; } public double getSalary() { return salary; } public void setSalary( double salary ) { this.salary = salary; } abstract void calculateSalary(); @Override public String toString() { final StringBuilder sb = new StringBuilder("Employee{"); sb.append("name='").append(name).append('''); sb.append(", salary=").append(salary); sb.append(", tax_rate=").append(tax_rate); sb.append('}'); return sb.toString(); } } class HourlyBasedEmployee extends Employee { double hoursWorked; double hourlyRate; public HourlyBasedEmployee( String name, double hoursWorked, double hourlyRate ) { super(name); this.hoursWorked = hoursWorked; this.hourlyRate = hourlyRate; } public double getHoursWorked() { return hoursWorked; } public void setHoursWorked( double hoursWorked ) { this.hoursWorked = hoursWorked; } public double getHourlyRate() { return hourlyRate; } public void setHourlyRate( double hourlyRate ) { this.hourlyRate = hourlyRate; } @Override void calculateSalary() { double monthlySalary = this.hoursWorked * this.hourlyRate; this.setSalary(monthlySalary - monthlySalary * tax_rate / 100); } } class MonthlyPaidEmployee extends Employee { double annualSalary; public MonthlyPaidEmployee( String name, double annualSalary ) { super(name); this.annualSalary = annualSalary; } @Override void calculateSalary() { double monthlySalary = this.annualSalary / 12; this.setSalary(monthlySalary - monthlySalary * tax_rate / 100); } } public class Company { public static void main( String[] args ) { List empList = new ArrayList(); MonthlyPaidEmployee mpE1 = new MonthlyPaidEmployee("John William", 55675.00); MonthlyPaidEmployee mpE2 = new MonthlyPaidEmployee("Nancy William", 65675.00); HourlyBasedEmployee hpE1 = new HourlyBasedEmployee("Samira Monid", 7.50, 35); empList.add(mpE1); empList.add(mpE2); empList.add(hpE1); for( int i = 0; i