Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is Java Programing Question 4: (20 points): Write the equals() and hashCode(), compareTo() methods for the following GroceryBill class that will override the corresponding

This is Java Programing
image text in transcribed
image text in transcribed
Question 4: (20 points): Write the equals() and hashCode(), compareTo() methods for the following GroceryBill class that will override the corresponding Object class methods, compareTo() should compare the objects based on their total amount. Question 5: Implementation (40 pointa): Suppose a class GroceryBill keeps track of a list of items being purchased at a market: Method/Constructor Description public Grocery (Employee clergy constructs Gracevillohet for the apeland public void odd(Item public double get Total public void printReceipt adds to this bill's total returns the cost of these items prints a list of items GroceryBill objects interact with Item objects. An Item has the following public methods Method/Constructor Description public double getPrice returns the price for this item public double getDiscount returns the discount for this item For example, 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 above classes do not consider discounts. Every item in a bill is charged full price, and item discounts are ignored. Define a class DiscountBill that extends GroceryBill to compute discounts for preferred customers. The constructor for DiscountBill accepts a parameter for whether the customer should get the discount. Your class should adjust the amount reported by getTotal for preferred customers. For example, if the total would have been $80 but a preferred customer is getting $20 in discounts, then get Total should report the total as $60 for that customer. You should also keep track of how many items a customer is getting a non-zero discount for and the overall discount, both as a total amount and as a percentage of the original bill. Include the extra methods below that allow a client to ask about the discount: Description constructs discount bill for given clerk Method/Constructor public DiscountBill(Employee clerk, boolean preferred) public int getDiscount Count public double getDiscount Amount returns the number of items that were discounted, if any returns the total discount for this list of items, if any returns the percent of the total discount as a percent of what the total would have been otherwise public double getDiscount Percent If the customer is not a preferred customer the DiscountBill behaves at all times as if there is a total discount of 0.0 and no items have been discounted. Question 4: (20 points): Write the equals() and hashCode(), compareTo() methods for the following GroceryBill class that will override the corresponding Object class methods, compareTo() should compare the objects based on their total amount. Question 5: Implementation (40 pointa): Suppose a class GroceryBill keeps track of a list of items being purchased at a market: Method/Constructor Description public Grocery (Employee clergy constructs Gracevillohet for the apeland public void odd(Item public double get Total public void printReceipt adds to this bill's total returns the cost of these items prints a list of items GroceryBill objects interact with Item objects. An Item has the following public methods Method/Constructor Description public double getPrice returns the price for this item public double getDiscount returns the discount for this item For example, 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 above classes do not consider discounts. Every item in a bill is charged full price, and item discounts are ignored. Define a class DiscountBill that extends GroceryBill to compute discounts for preferred customers. The constructor for DiscountBill accepts a parameter for whether the customer should get the discount. Your class should adjust the amount reported by getTotal for preferred customers. For example, if the total would have been $80 but a preferred customer is getting $20 in discounts, then get Total should report the total as $60 for that customer. You should also keep track of how many items a customer is getting a non-zero discount for and the overall discount, both as a total amount and as a percentage of the original bill. Include the extra methods below that allow a client to ask about the discount: Description constructs discount bill for given clerk Method/Constructor public DiscountBill(Employee clerk, boolean preferred) public int getDiscount Count public double getDiscount Amount returns the number of items that were discounted, if any returns the total discount for this list of items, if any returns the percent of the total discount as a percent of what the total would have been otherwise public double getDiscount Percent If the customer is not a preferred customer the DiscountBill behaves at all times as if there is a total discount of 0.0 and no items have been discounted

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

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

What would I do next and why?

Answered: 1 week ago