Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class DiscountBill extends GroceryBill { private boolean preferredCustomer; private int discountCount; private double totalDiscountAmount; / / Constructor for DiscountBill public DiscountBill ( Employee clerk,
public class DiscountBill extends GroceryBill
private boolean preferredCustomer;
private int discountCount;
private double totalDiscountAmount;
Constructor for DiscountBill
public DiscountBillEmployee clerk, boolean preferred
superclerk;
preferredCustomer preferred;
discountCount ;
totalDiscountAmount ;
Overrides add method to compute discounts for preferred customers
@Override
public void addItem i
super.addi;
if preferredCustomer && igetDiscount
discountCount;
totalDiscountAmount igetDiscount;
Overrides getTotal method to apply discounts for preferred customers
@Override
public double getTotal
double total super.getTotal;
if preferredCustomer
total totalDiscountAmount;
return total;
Returns the number of items that were discounted, if any
public int getDiscountCount
return discountCount;
Returns the total discount for this list of items, if any
public double getDiscountAmount
return totalDiscountAmount;
Returns the percent of the total discount as a percent of what the total would have been otherwise
public double getDiscountPercent
if preferredCustomer
double originalTotal super.getTotal totalDiscountAmount;
return totalDiscountAmount originalTotal;
else
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started