This example asks you to write an interface. Then define three classes that implement this interface. 1) Create an interface Discount Policy. It should have a single abstract method called computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and item Cost. This interface has no other method. 2) Define a class Bulk Discount that implements the interface Discount Policy, as de- scribed above. It should have a constructor that has two parameters, minimum and percent. It should define the method computeDiscount so that if the quantity purchased of an item is more than minimum, the discount is percent percent. 3) Define another class Buy NItemsGetOneFree that implements Discount Policy as de- scribed in part 1. The class should have a constructor that has a single parameter n. In addition, the class should define the method computeDiscount so that every nth item is free. For ex- ample, the following table gives the discount for the purchase of various counts of an item that costs $10, when n is 3. 1 2 Count Discount 0 3 4 5 10 | 10 | 10 6 20 7 20 0 4) Define a class Combined Discount that implements Discount Policy, as described in part1. It should have a constructor that has two parameters of type Discount Policy. It should define the method computeDiscount to return the maximum value returned by compute- Discount for each of its two private discount policies. The two discount policies are described in parts 2 and 3

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter10: Introduction To Inheritance
Section: Chapter Questions
Problem 20RQ
icon
Related questions
Question

This example asks you to write an interface. Then define three classes that implement this interface. 1) Create an interface Discount Policy. It should have a single abstract method called computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and item Cost. This interface has no other method. 2) Define a class Bulk Discount that implements the interface Discount Policy, as de- scribed above. It should have a constructor that has two parameters, minimum and percent. It should define the method computeDiscount so that if the quantity purchased of an item is more than minimum, the discount is percent percent. 3) Define another class Buy NItemsGetOneFree that implements Discount Policy as de- scribed in part 1. The class should have a constructor that has a single parameter n. In addition, the class should define the method computeDiscount so that every nth item is free. For ex- ample, the following table gives the discount for the purchase of various counts of an item that costs $10, when n is 3. 1 2 Count Discount 0 3 4 5 10 | 10 | 10 6 20 7 20 0 4) Define a class Combined Discount that implements Discount Policy, as described in part1. It should have a constructor that has two parameters of type Discount Policy. It should define the method computeDiscount to return the maximum value returned by compute- Discount for each of its two private discount policies. The two discount policies are described in parts 2 and 3.

Expert Solution
steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Introduction to Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,