Question

In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate...

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;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.*;

interface PensionScheme
{
public double calculatePension();
}
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 monthly PensionScheme for all Employee are: ");
     for (i = 0; i < 3; i++) System.out.println(staff[i].calculatePension());
   }
}

class Day
{
private int day;
private int month;
private int year;

public Day()
{
day = 0;
month = 0;
year = 0;
}
public Day(int year,int month,int day)
{
this.day = day;
this.month = month;
this.year = year;
}

public int getDay()
{
return day;
}
public int getMonth()
{
return month;
}
public int getYear()
{
return year;
}
}
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 = (2018 - hireYear())*salary;// difference of hiring year and 2018
       return Pension/12;
   }
   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 * (2018 - hireYear());
      super.raiseSalary(byPercent + bonus);
   }
  
   public void setSecretaryName(String n)
   { secretaryName = n;
   }
   public String getSecretaryName()
   { return secretaryName;
   }
  
   private String secretaryName;
}

output:

Harry Hacker 36750.0 1989
Carl Cracker 90375.0 1987
Tony Tester 39900.0 1990
The monthly PensionScheme for all Employee are:
88812.5
233468.75
93100.0

Add a comment
Know the answer?
Add Answer to:
In the Employee class, add an implementation for the calculatePension() method declared in the interface. Calculate...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA: How do I output all the data included for each employee? I can only get...

    JAVA: How do I output all the data included for each employee? I can only get it to output the name, monthly salary and annual salary, but only from the Employee.java file, not Salesman.java or Executive.java. Employee.java package project1; public class Employee { private String name; private int monthlySalary; public Employee(String name, int monthlySalary) { this.name = name; this.monthlySalary = monthlySalary; } public int getAnnualSalary() { int totalPay = 0; totalPay = 12 * monthlySalary; return totalPay; } public String...

  • departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE =...

    departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee;    } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...

  • DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to...

    DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to be DataSetEmployee. DataSetEmployee should extend ArrayList<Employee> and have no instance variables. You'll have to decide what replaces the getPages concept for getMax/getMin. As a hint, what method of Employee returns a numeric value? Make a package com.acme.midmanager. This package should contain the Manager class. Make a package com.acme.personnel. This package should contain the DataSetEmployee class. Make a package com.acme.topmanagement. This package should contain the...

  • Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee...

    Rewrite following code down below using Factory Pattern. -------------------------Staff.java--------------------------- import java.util.*; public class Staff extends Employee {    private int HourlyRate;    /**Constructor Staff which initiates the values*/    public Staff() {    super();    HourlyRate=0;    }    /**Overloaded constructor method    * @param ln last name    * @param fn first name    * @param ID Employee ID    * @param sex Sex    * @param hireDate Hired Date    * @param hourlyRate Hourly rate for the work...

  • //*Manager.java*// public interface Manager { public void handleCrisis(); } _________________________________________________________ /**Employee.java**/ Public abstract class Employee {...

    //*Manager.java*// public interface Manager { public void handleCrisis(); } _________________________________________________________ /**Employee.java**/ Public abstract class Employee { protected final String name; protected final int id; public Employee(String empName, int empId) { name = empName; id = empId; } public Employee() { name = generatedNames[lastGeneratedId]; id = lastGeneratedId++; } public String getName() { return name; } public int getId() { return id; } //returns true if work was successful. otherwise returns false (crisis) public abstract boolean work(); public String toString() { return...

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

  • 4. Create a Business class. This class should store an array of Employee objects. Add a...

    4. Create a Business class. This class should store an array of Employee objects. Add a method to add employees to the Business, similar to addFoodItem in the Meal class. Add two more methods for the Business class: getHighestPaid(), which returns the Employee who has been paid the most in total, and getHighestTaxed(), which returns the Employee who has been taxed the most in total. Note: you do not need to handle the case of ties. These are all the...

  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

  • Following is the EmployeeTester class, which creates object of the class Employee and calls the methods...

    Following is the EmployeeTester class, which creates object of the class Employee and calls the methods of that object. The EmployeeTester class is written to test another class: Employee. You are required to implement the class Employee by: declaring its instance variables: name, age, salary. implementing its constructor. implementing its methods: getEmployeeName(), getEmployeeAge(), getEmployeeSalary(), setEmployeeAge(int empAge),      setEmployeeSalary(double empSalary) public class EmployeeTester { public static void main(String args[]) { // Construct an object Employee employeeOne = new Employee("Ahmad Abdullah"); //...

  • In Java: Executable Class create an array of Employee objects. You can copy the array you...

    In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT