In: Computer Science
Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and itemCost.
Derive a class BulkDiscount from DiscountPolicy. 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 then minimum, the discount is percent percent.
//DiscountPolicy.java
public abstract class DiscountPolicy {
public abstract double computeDiscount(int count,
double itemCost);
}
//BulkDiscount.java
public class BulkDiscount extends DiscountPolicy {
int minimum;
double percent;
public BulkDiscount(int minimum, double percent)
{
this.minimum = minimum;
this.percent = percent;
}
@Override
public double computeDiscount(int count, double
itemCost) {
if (count > minimum) {
double discount
= itemCost * count * (percent / 100);
return
discount;
}
return 0;
}
}