Question: Help with below task to code a console application in language C# An Interface is typically used when unrelated classes need to share common methods.

Help with below task to code a console application in language C#

An Interface is typically used when unrelated classes need to share common methods. This allows objects of unrelated classes that implement the same interface, can respond to the same method calls. It means that all classes, which implement same interface, have to implement all its abstract methods.

Task is to create an interface named IPayable that describes the functionality of any object that must be capable of being paid and thus must offer a method to determine the proper payment amount. Look at the following hierarchy:

Help with below task to code a console application in language C#

Interface IPayable contains a method GetPaymentAmount that returns a decimal value. Classes Invoice and Employee (from previous task) both represent things for which the company must be able to calculate a payment amount.

Class Invoice contains three fields invoiceNumber (string can contain alphabets), quantity (int) and pricePerItem (decimal). One constructor with three arguments.

This task has two parts.

Part A:

Implement the interface and the class invoice. Create two objects of Invoice inside the Main method and call the method GetPaymentAmount (return value can be a multiply of quantity and pricePerItem).

Part B:

Modify task 2 so that the class Employee also implements the interface IPayable and make the changes that are needed in the classes, accordingly. Note that the method GetPaymentAmount will be an abstract method in Employee and it will be overridden in the other classes. The method implementation can be decided by you. You can replace Earning method with that method or you can choose to use Earning method inside the GetPaymentAmount in order to calculate for example monthly salary.

Create an array of type IPayable and size 4. Create some objects of different classes and put them in your array. Create a for-loop that goes through the array and call the method GetPaymentAmount.

> IPayable Invoice Employee SalariedEmployee

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!