Reject an invalid discount
A custom exception gives a business rule its own type.
Your task
Make a discount policy throw a custom exception for percentages outside 0 to 50, and print the error message when it does.
class DiscountPolicy {
public Decimal apply(Decimal amount, Decimal percent) {
return null;
}
}Requirements
throw new DiscountRangeExceptionshould be presentcatch (DiscountRangeExceptionshould be present- The error message should be built from the
percentvalue Valid: 150.00should be printedExactly 50: 100.00should be printedOver limit: 51% exceeds 50%should be printedBelow zero: -5% is below 0%should be printed