Question
Add two custom exceptionsclass. One should be checked exception and other should be unchecked exception. You have to handle both exceptions your code. class BaseSalariedCommissionEmployee
Add two custom exceptionsclass. One should be checked exception and other should be unchecked exception. You have to handle both exceptions your code.
class BaseSalariedCommissionEmployee extends Employee { //attributes private double baseSalary; private double sales; private double commissionPercent; //constructor public BaseSalariedCommissionEmployee(String name, Date birthDate, double baseSalary, double sales, double commissionPercent) { super(name, birthDate); this.baseSalary = baseSalary; this.sales = sales; this.commissionPercent = commissionPercent; } @Override public double pay() { return baseSalary + sales*commissionPercent/100; } @Override public String toString() { return "BaseSalariedCommissionEmployee [baseSalary=" + baseSalary + ", sales=" + sales + ", commissionPercent=" + commissionPercent + ", pay()=$" + pay() + "]"; } } class CommissionEmployee extends Employee { //attributes private double sales; private double commissionPercent; //constructor public CommissionEmployee(String name, Date birthDate, double sales, double commissionPercent) { super(name, birthDate); this.sales = sales; this.commissionPercent = commissionPercent; } @Override public double pay() { return sales * commissionPercent / 100; } @Override public String toString() { return "CommissionEmployee [sales=" + sales + ", commissionPercent=" + commissionPercent + ", pay()=$" + pay() + "]"; } } public class Date { private int Day; private int Month; private int Year; public Date(int Day, int Mont, int Year) {setYear(Year); } public Date() { } public void setDay(int Day) { if (Day <= 30) { this.Day = Day; } else { System.out.println("Invalid input"); } } public void setMonth(int Month) { if (Month<=12) { this.Month=Month; } else { System.out.println("Invalid input"); } } public void setYear(int year) { this.Year=Year; } public int getDay() { return Day; } public int getMonth() { return Month; } public int getYear() { return Year; } } abstract class Employee { private String name; private Date birthDate; public Employee(String name, Date birthDate) {this.name = name; this.birthDate = birthDate; } public Date getBirthDate(){ return birthDate; } //abstract method abstract double pay(); } class HourlyEmployee extends Employee { //attributes private int workedHours; private double wagePerHour; //constructor public HourlyEmployee(String name, Date birthDate, int workedHours, double wagePerHour) { super(name, birthDate); this.workedHours = workedHours; this.wagePerHour = wagePerHour; } @Override public double pay() { if(workedHours > 40) return 40 * wagePerHour + (workedHours - 40) * wagePerHour * 1.5; return workedHours * wagePerHour; } @Override public String toString() { return "HourlyEmployee [workedHours=" + workedHours + ", wagePerHour=" + wagePerHour + ", pay()=$" + pay() + "]"; } } class PieceWorker extends Employee { //attributes private double wage; private int pieces; //constructor public PieceWorker(String name, Date birthDate, double wage, int pieces) { super(name, birthDate); this.wage = wage; this.pieces = pieces; } @Override public double pay() { return wage*pieces; } @Override public String toString() { return "PieceWorker [wage=" + wage + ", pieces=" + pieces + ", pay()=$" + pay() + "]"; } }class SalariedEmployee extends Employee { private double basicSalary; public SalariedEmployee(String name, Date birthDate, double basicSalary) { super(name, birthDate); this.basicSalary = basicSalary; } @Override public double pay() { return basicSalary; } @Override public String toString() { return "SalariedEmployee [basicSalary=" + basicSalary + ", pay()=$" + pay() + "]"; } } public class TestEmployees { public static void main(String[] args){ Employee emp[] = new Employee[5]; emp[0] = new SalariedEmployee("Ali", new Date(5, 8, 1990), 5000); emp[1] = new HourlyEmployee("Ahmad", new Date(19, 6, 2000), 100, 10); emp[2] = new CommissionEmployee("Ahsan", new Date(10, 11, 1990), 12000, 10); emp[3] = new BaseSalariedCommissionEmployee("Saad", new Date(10, 1, 1990), 3000, 12000, 10); emp[4] = new PieceWorker("Qasim", new Date(10, 11, 2000), 300, 1200); Date date = new Date(); for(int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started