Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program: Supermarket Promotions Even though this assignment carries a lot of points, it's smaller and easier than the last two assignments. Hopefully
Write a program: Supermarket Promotions Even though this assignment carries a lot of points, it's smaller and easier than the last two assignments. Hopefully this will give you an opportunity to get the SmartShelf in order if you have fallen behind. We will keep adding features to our supermarket so that we can have a Grand Finale at the end of the semester when all of them are working together. For this assignment we will be using some classes from our SmartShelf project, and we will enhance them a little bit, but there will be no major changes to our existing functionality. Your goal is to create a promotion feature for our supermarket. A promotion has a name, a discount rate, an expiration date, and a set of items it applies to. The supermarket has a list of active promotions that can determine the best discount for a given item based on what promotions apply to it. As in the real life, promotions cannot be combined. You should also write a demo program that tests your implementation. The demo program needs to instantiate three different promotions with different discount rates. You then need to add all chips items to the first one, all cereal items to the second one, and all even cereal and chips items in your original unsorted lists to the third one. You can then run through the list of cereals and chips and find the best promotion that applies. Your project should have the following: You should create an enumeration RetailItemType that will have four possible values, CEREAL, CHIPS, SODA, and SOAP. (1 point) You should enhance your RetailItem class: In addition to its immutable name it should also have an immutable field type of the RetailItemType enumeration type (1 point) It should override the hashCode () method using its two fields (2 points) It should also override the equals () method in strict adherence to the equals () contract. (3 points) Its compareTo() method should now use the concatenation of the String representation of the type and the name to compare two RetailItems. (1 point) Both subclasses of RetailItem, Cereal and Chips now need to pass their respective RetailItemTypes to super () in their constructors (2 points) Your findAndTake () method of Smart Shelf class, and IShelfCustomer interface needs to take an additional RetailItemType parameter. (2 points) Your takeFromShelf () method of the Customer class also needs to take an additional RetailItemType parameter. (1 point) All the above tasks are a part of a typical refactoring exercise resulting from adding a retail item type to retail items. Your IDE should guide you through this process without much trouble. When it's all done your SmartShelf and SmartShelf Demo should work as before we will need this in the future. - Now the new code: You should create a Promotion class. This class should have the following: Four private immutable fields and a constructor that initializes them: (4 points) name O discount percentage o expiration date - use java.time.LocalDate to hold the date value a set of items the promotion applies to - use a HashSet to hold the items Getters for all of them except the item set (1 point) A public method determine Discount () that takes a retail item and returns the promotion discount percentage if the promotion applies to it and 0 otherwise (1 point) A public method addItem() that takes a retail item and adds it to the set of items (1 point) A public method addAllItems () that takes a Collection of items and adds all of its items. This method should be generic - make sure to create the correct type parameter for it. (2 points) You should create an Active Promotions class. This class should have the following: . . A List of active promotions. Think of what List implementation is most suitable (1 point) A method to add a promotion to the list (1 point) A method to remove a promotion with a given name from the list. You should use an iterator to iterate through the list and remove the promotion if found (2 points) A method to remove all expired promotions from the list. You should use an iterator to iterate through the list and remove all expired promotions if found. Use is Before () method of LocalDate to determine if a promotion has expired (2 points) A method that finds and returns the best promotion for a given item. Use the enhanced for loop to iterate over the list of promotions and ask each of them to determine the discount for the item (sequential search) (2 points) You should also create a Promotion Demo class. It should have method print Best Promos () that takes an ArrayList of items and an Acitve Promotions object and prints the best promotion for each member of the ArrayList. This method needs to be generic - think of a correct type parameter for it. (3 points) Its main () method needs to: o Create unsorted ArrayLists of cereals and chips - copy and paste from your SmartShelf demo (1 point) o Create three promotions with different names, discounts and expiration dates. One promotion should be expired. (1 point) o Add all chips to the first promo, all cereals to the second promo and all even elements of both chips and cereals to the third promo. (1 point) o Instantiate Active Promotions and add all three promotions to it. (1 point) Print the best promotions for each item of both ArrayLists by calling the print Best Promos () method. (1 point) o Remove the expired promotion (use LocalDate.now() for this) and print the best promotions for each item of both ArrayLists by calling the printBest Promos () again. (1 point) o Remove one of the remaining promotions by name and print the best promotions for each item of both ArrayLists by calling the print Best Promos () one more time. (1 point) Your output should look similar to this: Cereal: Corn Flakes Apple Jacks Reese's Puffs Honey Nut Cheerios Corn Flakes Apple Jacks Honey Nut Cheerios Raisin Bran Crunch Froot Loops Reese's Puffs Thanksgiving Columbus Thanksgiving Expires: 2021-11-28 Expires: 2021-10-11 Expires: 2021-11-28 20% 5% 20% Thanksgiving Expires: 2021-11-28 20% Thanksgiving Columbus Thanksgiving Columbus Thanksgiving Thanksgiving Expires: 2021-11-28 Expires: 2021-10-11 Expires: 2021-11-28 Expires: 2021-10-11 Expires: 2021-11-28 Expires: 2021-11-28 20% 5% 20% 5 % 20% 20% Corn Flakes Frosted Flakes. Lucky Charms Thanksgiving Honey Bunches of Oats Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 20% 20% 20% Thanksgiving Expires: 2021-11-28 20% Rice Krispies Fruity Pebbles Thanksgiving Columbus Expires: 2021-11-28 20% 5% Frosted Mini-Wheats Froot Loops 20% 20% Lucky Charms 20% 20% 20% 20% 20% 5 % 20% Cheerios Reese's Puffs Honey Nut Cheerios. Cheerios Cinnamon Toast Crunch Honey Bunches of Oats Froot Loops Frosted Flakes Honey Bunches of Oats Honey Nut Cheerios Chips: Expires: 2021-10-11 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 Columbus Expires: 2021-10-11 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 Thanksgiving Expires: 2021-11-28 20% 20% 20% 20% Doritos Pringles Lays Funyuns Cheetos Thanksgiving Expires: 2021-11-28 Halloween Expires: 2021-10-31 Thanksgiving Expires: 2021-11-28 Halloween Thanksgiving 20% 10% 20% Expires: 2021-10-31 10% Ruffles Halloween Fritos Takis Lays Funyuns. Cheetos Ruffles Fritos Expires: 2021-11-28 Expires: 2021-10-31 Thanksgiving Expires: 2021-11-28 Halloween Expires: 2021-10-31 Thanksgiving Expires: 2021-11-28 Halloween Expires: 2021-10-31 Thanksgiving Expires: 2021-11-28 Halloween Expires: 2021-10-31 Thanksgiving Expires: 2021-11-28 Halloween Expires: 2021-10-31 Thanksgiving Expires: 2021-11-28 Halloween 20% 10% 20% 10% 20% 10% 20% 10% 20% 10% 20% Expires: 2021-10-31 10% Takis Sun Chips Tostitos Removed expired Cereal: Corn Flakes Apple Jacks Reese's Puffs Honey Nut Cheerios Corn Flakes Apple Jacks Honey Nut Cheerios Raisin Bran Crunch Froot Loops Reese's Puffs: Corn Flakes Honey Bunches of Oats Frosted Flakes. Lucky Charms Thanksgiving Expires: 2021-11-28 20% No active promo Thanksgiving Expires: 2021-11-28 Thanksgiving 20% Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% No active promo Thanksgiving Expires: 2021-11-28 No active promo 20% Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Rice Krispies Fruity Pebbles Froot Loops Thanksgiving Expires: 2021-11-28 No active promo 20% Frosted Mini-Wheats Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Lucky Charms Cheerios Reese's Puffs. Honey Nut Cheerios Cheerios Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Cinnamon Toast Crunch Honey Bunches of Oats No active promo Thanksgiving Expires: 2021-11-28 20% Froot Loops Frosted Flakes Thanksgiving Expires: 2021-11-28 20% Thanksgiving Expires: 2021-11-28 20% Honey Bunches of Oats Thanksgiving Expires: 2021-11-28 20% Honey Nut Cheerios Thanksgiving Expires: 2021-11-28 20% Chips: Doritos. Pringles Lays Thanksgiving Halloween Expires: 2021-11-28 20% Expires: 2021-10-31 10% Thanksgiving Expires: 2021-11-28 20% Funyuns Cheetos Ruffles Fritos Takis Halloween Expires: 2021-10-31 10% Thanksgiving Expires: 2021-11-28 20% Halloween Expires: 2021-10-31 10% Thanksgiving Expires: 2021-11-28 20% Halloween Expires: 2021-10-31 10% Lays Thanksgiving Expires: 2021-11-28 20% Funyuns Halloween Expires: 2021-10-31 10% Cheetos Ruffles Thanksgiving Expires: 2021-11-28 20% Halloween Expires: 2021-10-31 10% Fritos Takis Thanksgiving Expires: 2021-11-28 20% Halloween Expires: 2021-10-31 10% Sun Chips Tostitos Removed Thanksgiving Cereal: Corn Flakes Thanksgiving Halloween Expires: 2021-11-28 20% Expires: 2021-10-31 10% No active promo Apple Jacks No active promo Reese's Puffs. No active promo Honey Nut Cheerios No active promo Corn Flakes No active promo Apple Jacks No active promo Honey Nut Cheerios No active promo Raisin Bran Crunch No active promo Froot Loops No active promo Reese's Puffs. No active promo Corn Flakes Frosted Flakes. Lucky Charms Rice Krispies No active promo Honey Bunches of Oats No active promo No active promo No active promo No active promo Fruity Pebbles No active promo Frosted Mini-Wheats No active promo Froot Loops No active promo Cheerios Lucky Charms Reese's Puffs Honey Nut Cheerios. Cheerios Cinnamon Toast Crunch Honey Bunches of Oats Froot Loops No active promo No active promo No active promo No active promo No active promo No active promo. No active promo No active promo Frosted Flakes. Honey Bunches of Oats Honey Nut Cheerios Chips: No active promo No active promo No active promo. Doritos Halloween Expires: 2021-10-31 10% Pringles Halloween Expires: 2021-10-31 10% Lays Halloween Expires: 2021-10-31 10% Funyuns Halloween Expires: 2021-10-31 10% Cheetos Halloween Expires: 2021-10-31 10% Ruffles Halloween Expires: 2021-10-31 10% Fritos Halloween Expires: 2021-10-31 10% Takis Halloween Expires: 2021-10-31 10% Lays Halloween Expires: 2021-10-31 10% Funyuns Halloween. Expires: 2021-10-31 10% Cheetos Halloween Expires: 2021-10-31 10% Ruffles Halloween Expires: 2021-10-31 10% Fritos Takis Halloween Expires: 2021-10-31 10% Halloween Expires: 2021-10-31 10% Sun Chips Halloween Expires: 2021-10-31 10% Tostitos Halloween. Expires: 2021-10-31 10% Notes: Your classes and methods should have javadocs. Uncommented code is an automatic 1-point deduction. Follow the Assignment documentation format (published in Canvas). Incorrectly formatted submissions will have an automatic 1-point deduction. Never edit the program output. Program output inconsistent with the code is an automatic 0 for the assignment.
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