Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Polymorphism in Java Question help Problem 1 Modify the Firm project discussed i

ID: 3826784 • Letter: P

Question

Polymorphism in Java Question help

Problem 1
Modify the Firm project discussed in class such that it accomplishes its polymorphism using an interface called Payable, containing the pay method.

Problem 2

Modify the Firm project such that staff members are sorted by their pay. If the pay is the same, their names are sorted.
The project, therefore, displays the pay information in that sorted order. You may use any of the written programs discussed in class.

HINT. You can use either selectionSort or insertionSort from the Sorting class. DO NOT change the class hierarchy.

Explanation / Answer

Hello,

I have implemented Part A wherin Interface named payable is declared whihc is extended by Class Firm and it in turns calls methodPay which is then calling payment details of employee and exeutive as well.

CODE:-

/*******************************************************************

//

//   Firm.java          In Text          Application

//

//   Authors: Lewis and Loftus

//

//   Classes: Firm

//             Employee

//             Executive

//

//*******************************************************************

//-------------------------------------------------------------------

//

// Class Firm contains the driver of a program that manages a set

// of employees also implements interface Payable which is given

//

// Methods:

//

//     public static void main (String[] args)

//     public void methodPay()

//     interface Payable is declared which will call method pay an then will be called in class Firm

//-------------------------------------------------------------------

interface Payable

{

    public void methodPay();

}

class Firm implements Payable

{

   //===========================================================

   // Creates several employees, including an executive, and

   // pays them.

   //===========================================================

   public static void main (String[] args) {

      Executive sam = new Executive ("Sam", "123 Main Line",

         "555-0469", "123-45-6789", 1923.07);

      Employee carla = new Employee ("Carla", "456 Off Line",

         "555-0101", "987-65-4321", 846.15);

      Employee woody = new Employee ("Woody", "789 Off Rocker",

         "555-0000", "010-20-3040", 769.23);

      Payable obj = new Firm();

      obj.methodPay();

      

      public void methodPay()

      {

       woody.print();

       System.out.println ("Paid: " + woody.pay());

       System.out.println();

       carla.print();

       System.out.println ("Paid: " + carla.pay());

       System.out.println();

       sam.print();

       sam.award_bonus (2000);

       System.out.println ("Paid: " + sam.pay());

       System.out.println();

      }

     

   } // method main

} // class Firm

//-------------------------------------------------------------------

//

// Class Employee represents one general employee of a company.

//

// Constructors:

//

//     public Employee (String emp_name, String emp_address,

//                      String emp_phone, String emp_ssnumber,

//                      double emp_rate)

//

// Methods:

//

//     public double pay ()

//     public void print ()

//

//-------------------------------------------------------------------

class Employee {

   protected String name;

   protected String address;

   protected String phone_number;

   protected String social_security_number;

   protected double pay_rate;

  

   //===========================================================

   // Sets up an employee with the specified information.

   //===========================================================

   public Employee (String emp_name, String emp_address,

                    String emp_phone, String emp_ssnumber,

                    double emp_rate) {

      name = emp_name;

      address = emp_address;

      phone_number = emp_phone;

     social_security_number = emp_ssnumber;

      pay_rate = emp_rate;

   } // constructor Employee

   //===========================================================

   // Returns the pay rate for this employee.

   //===========================================================

  

   public double pay () {

      return pay_rate;

   } // method pay

  

   //===========================================================

   // Prints the basic information about an employee.

   //===========================================================

   public void print () {

      System.out.println (name + "   " + social_security_number);

      System.out.println (address);

      System.out.println (phone_number);

   } // method print

} // class Employee

//-------------------------------------------------------------------

//

// Class Executive represents one executive, which is an employee

// that can possibly earn a bonus.

//

// Constructors:

//

//     public Executive (String exec_name, String exec_address,

//                       String exec_phone, String exec_ssnumber,

//                       double exec_rate)

//

// Methods:

//

//     public void award_bonus (double exec_bonus)

//     public double pay ()

//

//-------------------------------------------------------------------

class Executive extends Employee {

   private double bonus;

   //===========================================================

   // Sets up an executive with the specified information.

   //===========================================================

   public Executive (String exec_name, String exec_address,

                     String exec_phone, String exec_ssnumber,

                     double exec_rate) {

      super (exec_name, exec_address, exec_phone, exec_ssnumber,

             exec_rate);

      bonus = 0; // bonus yet to be awarded

   } // constructor Executive

   //===========================================================

   // Awards the specified bonus to this Executive.

   //===========================================================

   public void award_bonus (double exec_bonus) {

      bonus = exec_bonus;

   } // method award_bonus

   //===========================================================

   // Computes and returns the pay for an executive, which is

   // the regular salary plus a one-time bonue. Overrides

   // the pay method of the Employee class.

   //===========================================================

   public double pay () {

      double paycheck = super.pay() + bonus;

      bonus = 0;

      return paycheck;

   } // method pay

} // class Executive

===================================================================================

The edited code can be found in bold.Now for Part B.I need to modify the Employee class,Executive class as well

If it is allowed I can do it and upload the re-edited code.