Answered step by step
Verified Expert Solution
Link Copied!

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 DiscountBill(Employee clerk, boolean preferred){
super(clerk);
preferredCustomer = preferred;
discountCount =0;
totalDiscountAmount =0.0;
}
// Overrides add method to compute discounts for preferred customers
@Override
public void add(Item i){
super.add(i);
if (preferredCustomer && i.getDiscount()>0.0){
discountCount++;
totalDiscountAmount += i.getDiscount();
}
}
// 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)*100.0;
} else {
return 0.0;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming With Visual Basic .NET

Authors: Carsten Thomsen

2nd Edition

1590590325, 978-1590590324

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago