Text Share Online

3. An interface named Company has the following methods:

 

  • void assignSalaries(int[] salaries);
  • void averageSalary();
  • void maxSalary();
  • void minSalary();

 

Create 2 classes, EngineerFirm and AccountantFirm, that implement the Company interface. The details of these classes follow.

 

1. Class EngineerFirm should have a variable of type int[] income. It should implement the following methods:

  • EngineerFirm(int n):
    • Initializes the empty array income of length n where n is the number of engineers.
    • Assigns 0 income to all the engineers.
  • void assignSalaries(int[] salaries): Assigns the salaries in array salaries to array income.
    • If the salaries and income arrays differ in length, assigns as many values as possible and then stops.
    • Prints “Incomes of engineers credited”.
  • void averageSalary(): Prints the average salary in the format “Average salary of engineers is {averageSalary}“.
    • Zero values in income, if any, should be included in the average calculation.
  • void maxSalary(): Prints the maximum salary in the format “Maximum salary amongst engineers is {maximumSalary}“.
  • void minSalary(): Prints the minimum salary in the format “Minimum salary amongst engineers is {minimumSalary}“.

 

2. Class AccountantFirm should have a variable of type int[] income. It should implement the following methods:

  • AccountantFirm(int n):
    • Initializes the empty array income of length n where n is the number of accountants.
    • Assigns 0 income to each accountant.
  • void assignSalaries(int[] salaries): Assigns the salaries in array salaries to array income.  
    • If the salaries and income arrays differ in length, assigns as many values as possible and then stops.
    • Prints “Incomes of accountants credited”.
  • void averageSalary(): Prints the average salary in the format “Average salary of accountants is {averageSalary}“.
    • Zero values in income, if any, should be included in the average calculation.
  • void maxSalary(): Prints the maximum salary in the format “Maximum salary amongst accountants is {maximumSalary}“.
  • void minSalary(): Prints the minimum salary in the format “Minimum salary amongst accountants is {minimumSalary}“.

 

Note: Please use inheritance and encapsulation to minimize code repetition. The locked code stub provides the interface Company and also validates the implementation of the EngineerFirm and AccountantFirm classes.

 

Share This: