Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions