Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please do according to the description above. Thank you so much Fou will be creating classes and methods for a grocery store. Every item sold
Please do according to the description above.
Thank you so much
Fou will be creating classes and methods for a grocery store. Every item sold in a grocery store has a UPC (Universal Product Code) which is a numeric string. Create package com beans Create an abstract class called Item in the com.beans package with the attributes below. The Constructor takes parameters in the following order: the UPC and item's name. Create getters and setters. # com.beans Item upc: String .name : String Item(String, String) .getUpc(): String setUpc(String): void .getName(): String setName(String): void Create class called Groceryltem in the com.beans package. GroceryItem extends Item. Grocery items have additional class variables: company (for the company that makes the item ... for example: Kellogg's), the price of the item, and a loyalty code (which we'll explain in a bit). Create two constructors. One constructor will have parameters in the following order: UPC, item name, company, and price. The second constructor will have parameters in the following order: UPC, item name, company, price, and loyalty code. Create all getters and setters. Override the toString method. The class outline is shown on the next page. # com.beans Groceryltem e company: String . price: double loyaltyCode: String Groceryltem(String. String, String, double) Groceryltem(String, String, String, double, String) getCompany: String setCompany(String): void .getLoyaltyCode(): String SetLoyaltyCode(String): void getPrice: double setPrice(double): void toString(): String Grocery stores have loyalty cards. Customers with loyalty cards can save money on some groceries. This store has three types of deals: buy one get one, a percentage discount (ex: 10%), and a flat discount (ex: save 50 cents). Create an enum called DealType in the com.beans package and add the enums listed: com.beans DealType SF BUY_ONE_GET_ONE SF PERCENT_DISCOUNT SF FLAT_DISCOUNT Every loyalty deal has a UPC associated to it and a name for the type of deal it is. Create a LoyaltyDeal class in the com.beans. LoyaltyItem extends Item.. Loyalty deals have additional class variables: A deal type and a discount value. Create two constructors. One constructor will have parameters in this order: UPC, name, and deal type. The other constructor will have parameters in this order: UPC, name, deal type, and discount. Create getters and setters and override toString. The class outline is on the next page. # com.beans LoyaltyDeal . dealType: DealType discount : double LoyaltyDeal(String, String, DealType) LoyaltyDeal(String, String, DealType double) getDealType(): DealType setDealType(DealType) : void getDiscount(): double set Discount(double): void toString(): String Create a Demo class in the com.runner package. Copy and paste in the following code into your main method: public static void main(String[] args) { LoyaltyDeal] loyals = new LoyaltyDeal[4]; loyals[0] = new LoyaltyDeal ("70001", "BOGO", DealType.BUY_ONE_GET_ONE); loyals[1] new LoyaltyDeal("70002", "10% Off", DealType.PERCENT_DISCOUNT, 10); loyals[2] = new LoyaltyDeal ("70003", "50 Cents Off", DealType.FLAT_DISCOUNT, 0.5); loyals[3] = new LoyaltyDeal ("70004", "5% Off", DealType. PERCENT_DISCOUNT, 5); GroceryItem[] items = new GroceryItem[8]; items [0] = new Grocery Item("123", "Corn Flakes", "Kellogg's", 2.98); items[1] new Grocery Item("400", "Cupcakes", "Sunny", 3.19, "70001"); items [2] = new GroceryItem("201", "Paper Towels", "Pow", 2.60); items [3] = new Grocery Item("700", "Swiss Cheese", "Happy Cow", 2.99,"70001"); items [4] = new Grocery Item("305", "Corn Flakes", "Yum", 3.00, "70002"); items [5] = new Grocery Item("501", "Corn Flakes", "Big Box", 2.94, "70004"); items[6] = new Grocery Item("901", "Bleach", "Pow", 1.05); items [7] = new Grocery Item("305", "Corn Flakes", "Sunny", 3.30, "70003"); double price = GroceryUtilities. adjustUPCItemCost(items[2], 10); System.out.println(price + " should equal items [2].getPrice); + System.out.println(); Grocery Item[] dealItems = GroceryUtilities.getALlItemsForLoyaltyDeal (items, loyals[0]); for (GroceryItem dealItem: dealItems) { System.out.println(dealItem); } Create a class called Grocery Utilities in the com utilities package. You will be writing four methods total! If you want to add private methods to simplify your code, you can do so. Code for testing the first two methods can be found in the Demo class (shown above). You will need to write methods to test the two remaining methods in the Demo class. The first two methods in the GroceryUtilites class are shown in this outline and are explained on the next page: # com.utils GroceryUtilities adjustUPCItemCost(Groceryltem, int): double getAltemsForLoyaltyDeal(Groceryltem[], LoyaltyDeal): Groceryltem[] METHOD ONE Method adjustUPCItemCost will take one Groceryltem object and double. The double represents the percentage out of 100. Method will update the price of the grocery item by decreasing it by percentage and the method will return the updated price. For example: double price = GroceryUtilities.adjustUPCItemCost(items[2], 10); This should reduce the price of item[2] by 10%. The resulting cost will be: 2.34 If instead, I passed in (items[2], 5), the resulting cost will be: 2.47 METHOD TWO method getAllItemsForLoyaltyDeal will take an array of Groceryltem and a LoyaltyDeal object. The method will return an array of grocery items that have that loyalty deal. In other words, if the loyalty deal's UPC matches the grocery item's loyaltyCode that item will be added to the array that is returned from this method. For example: GroceryItem[] dealItems = GroceryUtilities.getALlItemsForLoyaltyDeal (items, lovals[0]); This method should return an array with two items: The item with UPC 400 (Cupcakes) and the item with UPC 700 (Swiss Cheese). Those items both have a loyalty code that matches the UPC of that loyalty deal. If I passed in loyals[3], the method would return an array with only one item: The item with UPC 501 (Corn Flakes). Next, add TWO MORE METHODS_to GrocecxUtilies class: METHOD THREE public static HashSetStep 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