Question
In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate the pension to date as the equivalent of a
In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate the pension to date as the equivalent of a monthly salary for every year in service. 4) Print the calculated pension for all employees.
************** I added the interface and I implemented the interface with Employee class but, I don't know how can i call the method in main class ************
import java.io.*;
public class ManagerTest { public static void main(String[] args) { InputStreamReader isr = null; // BufferedReader br = null;
Employee[] staff = new Employee[3];
staff[0] = new Employee("Harry Hacker", 35000, new Day(1989,10,1)); staff[1] = new Manager("Carl Cracker", 75000, new Day(1987,12,15)); staff[2] = new Employee("Tony Tester", 38000, new Day(1990,3,15)); int i; for (i = 0; i < 3; i++) staff[i].raiseSalary(5); for (i = 0; i < 3; i++) staff[i].print(); System.out.println("The PensionScheme for all Employee are: ");
} }
class Employee implements PensionScheme { public Employee(String n, double s, Day d) { name = n; salary = s; hireDay = d; } public void print() { System.out.println(name + " " + salary + " " + hireYear()); } public void raiseSalary(double byPercent) { salary *= 1 + byPercent / 100; //assume myPrecent=5. salary * 5 / 100 } public int hireYear() { return hireDay.getYear(); } @Override public double calculatePension() { Day today = new Day(); double Pension = (today.getYear() - hireYear())*salary; return Pension; } private String name; private double salary; private Day hireDay; }
class Manager extends Employee { public Manager(String n, double s, Day d) { super(n, s, d); secretaryName = ""; }
public void raiseSalary(double byPercent) { // add 1/2% bonus for every year of service Day today = new Day(); double bonus = 0.5 * (today.getYear() - hireYear()); super.raiseSalary(byPercent + bonus); } public void setSecretaryName(String n) { secretaryName = n; }
public String getSecretaryName() { return secretaryName; } private String secretaryName; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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