Write an interface Discountable with a constant MAX_RATE = 0.5, an abstract method double discountRate() and a default method double discountOn(double price) that returns price × min(rate, MAX_RATE).
Write an abstract class Item (name, price, finalPrice() that applies the discount only if this instanceof Discountable) and three subclasses:
Book— never discounted (does not implement the interface);Food(name, price, daysToExpiry)— implements it: 60 % when ≤ 1 day left (capped at 50 %), 30 % when ≤ 3 days, else 0;Electronics(name, price, openBox)— implements it: 15 % if open box, else 5 %.
Checkout.main reads book NAME PRICE, food NAME PRICE DAYS or tech NAME PRICE true|false until the end of input, prints each line (%-12s %8.2f plus (-3.00) if discounted), Total …, you saved … and 2 of 3 items can be discounted.