Java Reference
In-Depth Information
9. DiscountBill . Suppose a class GroceryBill keeps track of a list of items being purchased at a market:
Constructs a grocery bill object for the given clerk
public GroceryBill(Employee clerk)
Adds the given item to this bill
public void add(Item i)
Returns the total cost of these items
public double getTotal()
Prints a list of items
public void printReceipt()
Grocery bills interact with Item objects, each of which has the public methods that follow. A candy bar item might
cost 1.35 with a discount of 0.25 for preferred customers, meaning that preferred customers get it for 1.10. (Some
items will have no discount, 0.0.) Currently the preceding classes do not consider discounts. Every item in a bill is
charged full price, and item discounts are ignored.
Returns the price for this item
public double getPrice()
Returns the discount for this item
public double getDiscount()
Define a class DiscountBill that extends GroceryBill to compute discounts for preferred customers. Its con-
structor accepts a parameter for whether the customer should get the discount. Your class should also adjust the total
reported for preferred customers. For example, if the total would have been $80 but a preferred customer is getting
$20 in discounts, then getTotal should report the total as $60 for that customer. Also keep track of the number of
items on which a customer is getting a nonzero discount and the sum of these discounts, both as a total amount and
as a percentage of the original bill. Include the extra methods that follow, which allow a client to ask about the dis-
count. Return 0.0 if the customer is not a preferred customer or if no items were discounted.
Constructs bill for given clerk
public DiscountBill(Employee
clerk, boolean preferred)
public int getDiscountCount()
Returns the number of items that were discounted, if any
Returns the total discount for this list of items, if any
public double getDiscountAmount()
Returns the percent of the total discount as a percent of what
the total would have been otherwise
public double getDiscountPercent()
10. FilteredAccount . A cash processing company has a class called Account used to process transactions:
Constructs an account using client information
public Account(Client c)
Processes the next transaction, returning true if
the transaction was approved and false otherwise
public boolean process(Transaction t)
 
Search WWH ::




Custom Search