Question 01: Implement the following UML class diagrams which include an abstract class Employee, an interface TaxCalculator, and a child class Faculty. Employee > TaxCalculator +TAX PERCENT Hinta 15 – id:int name : String – age : int + yearlyIncome Tax(: double + yearlyIncome WithoutTax(: double Employee (id: int, name: String, age int) + Getters + Setters + yearlySalaryo : int //abstract + yeanyIncome() : int l’abstract Faculty – initial : String monthly Salary: int – yearlyBonus : int + Faculty (id:int, name : String, age : int, initial : String, monthly Salary: int, yearlyBonus : int) + Getters + Setters + toString : String Now write a test program that performs the following tasks: 1. Create a Faculty object with an id of 1001, name as Gareth Bale, age of 43 years, initial as GB, the monthly salary of 30000 BDT, the yearly bonus of 40000 BDT. 2. Call the toString() method of the Faculty class where yearlySalary.yearlylncome, yearlyIncome Tax, yearlyIncome Without Tax are included. In console: Faculty (initial=GB, monthlySalary=30000, yearlyBonus=40000, yearlySalary=360000, yearlyIncome=400000, yearlyIncome Tax=60000.0, yearlyIncome Without Tax=340000.0 3. Now modify the Faculty class in such a way so that objects can’t be created with a negative yearly bonus. If any Faculty object is created with a negative yearly bonus, it’ll throw an exception such as IllegalArgumentException with an appropriate error message like “Yearly bonus can’t be negative”. 4. Create another Faculty object with an id of 1002, name as lan Goodfellow, age of 46 years, initial as IGF, the monthly salary of 30000 BDT, the yearly bonus of – 40000 BDT. 5. Then catch with an appropriate error message, if any exception occurs here.

28 0

Get full Expert solution in seconds

$1.97 ONLY

EXPERT ANSWER

TaxCalculator.java

package com.ankush.chegg;

public interface TaxCalculator {

        
        int tax_percent=15;
        
        public double yearlyIncomeTax();
        
        public double yearlyIncomeWithoutTax();
}

Step 2 :

package com.ankush.chegg;

public abstract class Employee {
        
        private int id;
        private String name;
        private int age;
        
        public Employee(int id, String name, int age) {
                super();
                this.id = id;
                this.name = name;
                this.age = age;
        }

        public int getId() {
                return id;
        }

        public void setId(int id) {
                this.id = id;
        }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public int getAge() {
                return age;
        }

        public void setAge(int age) {
                this.age = age;
        }
        
        
        public abstract int yearlySalary();
        
        public abstract int yearlyIncome();
        

}

Step 3:

Faculty.java

package com.ankush.chegg;

public class Faculty extends Employee implements TaxCalculator {
        
        private String initial;
        private int monthlySalary;
        private int yearlyBonus;
        
        
        public Faculty(int id,String name,int age,String initial, int monthlySalary, int yearlyBonus) {
                super(id, name, age);
                this.initial = initial;
                this.monthlySalary = monthlySalary;
                this.yearlyBonus = yearlyBonus;
        }
public String getInitial() {
                return initial;
        }


        public void setInitial(String initial) {
                this.initial = initial;
        }


        public int getMonthlySalary() {
                return monthlySalary;
        }


        public void setMonthlySalary(int monthlySalary) {
                this.monthlySalary = monthlySalary;
        }


        public int getYearlyBonus() {
                return yearlyBonus;
        }


        public void setYearlyBonus(int yearlyBonus) {
                this.yearlyBonus = yearlyBonus;
        }


        @Override
        public String toString() {
                return "Faculty [initial=" + initial + ", monthlySalary=" + monthlySalary + ", yearlyBonus=" + yearlyBonus
                                + "]";
        }


        @Override
        public int yearlySalary() {
                
                
                
                return monthlySalary*12;
        }

        
        @Override
        public int yearlyIncome() {
                // TODO Auto-generated method stub
                
                
                 if (yearlyBonus < 0) {
             throw new IllegalArgumentException(
                     "Yearly Bonus can't be negative.");
         }
                
                 else {
                return  (monthlySalary*12+ yearlyBonus);
                
                 }
        }

        

        @Override
        public double yearlyIncomeTax() {
                // TODO Auto-generated method stub
        
                 if (yearlyBonus < 0) {
             throw new IllegalArgumentException(
                     "Yearly Bonus can't be negative.");
         }
                
                 else           
                 {
                
                double yearlyIncomeTax=(monthlySalary*12)*tax_percent/100;
                
                return yearlyIncomeTax;
                 }      
                
        }


        @Override
        public double yearlyIncomeWithoutTax() {
                
        
                 if (yearlyBonus < 0) {
             throw new IllegalArgumentException(
                     "Yearly Bonus can't be negative.");
         }
                

                 else
                 {
                
                double yearlyIncomeTax=(monthlySalary*12)*tax_percent/100;
                
                double yearlyIncomeWithoutTax= (monthlySalary*12+ yearlyBonus)-yearlyIncomeTax;
                
                
                return yearlyIncomeWithoutTax;
                
                                }
                        }


                }

Step 4 :

Test.java

package com.ankush.chegg;

public class Test {
        

        public static void main(String[] args) {
                
                Faculty fac=new Faculty(1001, "Gareth Bale", 43, "GB",30000, 40000);
                
                
                System.out.println("Salary : "+fac.yearlySalary());
                
                System.out.println("Yearly Income : "+fac.yearlyIncome());
                
                System.out.println("Yearly Income tax : "+fac.yearlyIncomeTax());
                
                System.out.println("Yearly Income without tax : "+fac.yearlyIncomeWithoutTax());
                
    }  

}

Step 5 :

*********output***********

Step 6 : If Bonus less than 0 shown below output