Question: public interface Carryable { public String getContents(); public String getDescription(); public float getPrice(); } public class FreezerItem extends PerishableItem { public FreezerItem(String n, float p,

 public interface Carryable { public String getContents(); public String getDescription(); publicfloat getPrice(); } public class FreezerItem extends PerishableItem { public FreezerItem(String n,

public interface Carryable { public String getContents(); public String getDescription(); public float getPrice(); } 
public class FreezerItem extends PerishableItem { public FreezerItem(String n, float p, float w) { super(n, p, w); } public String toString () { return super.toString() + "[keep frozen]"; } } 
public class GroceryBag implements Carryable { public static final float MAX_WEIGHT = 5; // max weight allowed (kg)  public static final int MAX_ITEMS = 25; // max # items allowed   private GroceryItem[] items; // actual GroceryItems in bag  private int numItems; // # of GroceryItems in bag  private float weight; // current weight of bag   public GroceryBag() { items = new GroceryItem[MAX_ITEMS]; numItems = 0; weight = 0; } public GroceryItem[] getItems() { return items; } public int getNumItems() { return numItems; } public float getWeight() { return weight; } public String toString() { if (weight == 0) return "An empty grocery bag"; return ("A " + weight + "kg grocery bag with " + numItems + " items"); } public boolean canHold(GroceryItem g) { return (((weight + g.getWeight()) public void addItem(GroceryItem g) { if (canHold(g)) { items[numItems++] = g; weight += g.getWeight(); } } public void removeItem(GroceryItem item) { for (int i = 0; i if (items[i] == item) { weight -= items[i].getWeight(); items[i] = items[numItems - 1]; numItems -= 1; return; } } } // Finds and returns the heaviest item in the shopping cart  public GroceryItem heaviestItem() { if (numItems == 0) return null; GroceryItem heaviest = items[0]; for (int i=0; iif (items[i].getWeight() > heaviest.getWeight()) { heaviest = items[i]; } } return heaviest; } // Determines whether or not the given item in the shopping cart  public boolean has(GroceryItem item) { for (int i = 0; i if (items[i] == item) { return true; } } return false; } // Remove all perishables from the bag and return an array of them  public PerishableItem[] unpackPerishables() { int perishableCount = 0; for (int i=0; iif (items[i] instanceof PerishableItem) perishableCount++; } PerishableItem[] perishables = new PerishableItem[perishableCount]; perishableCount = 0; for (int i=0; iif (items[i] instanceof PerishableItem) { perishables[perishableCount++] = (PerishableItem)items[i]; removeItem(items[i]); i--; } } return perishables; } public String getDescription() { return "GROCERY BAG (" + weight + "kg)"; } public String getContents(){ String result = ""; for (int i=0; i" " + items[i] + " "; return result; } public float getPrice() { float total = 0; for (int i=0; ireturn total; } } 
public class GroceryItem implements Carryable{ private String name; private float price; private float weight; public GroceryItem() { name = "?"; price = 0; weight = 0; } public GroceryItem(String n, float p, float w) { name = n; price = p; weight = w; } public String getName() { return name; } public float getPrice() { return price; } public float getWeight() { return weight; } public String toString () { return name + " weighing " + weight + "kg with price $" + price; } public String getDescription() { return name; } public String getContents(){ return ""; } } 
public abstract class PerishableItem extends GroceryItem { public PerishableItem(String n, float p, float w) { super(n, p, w); } public String toString () { return super.toString() + " (perishable)"; } } 
public class RefrigeratorItem extends PerishableItem { public RefrigeratorItem(String n, float p, float w) { super(n, p, w); } public String toString () { return super.toString() + "[keep refrigerated]"; } } 
public class Shopper { public static final int MAX_CART_ITEMS = 100; // max # items allowed   private Carryable[] cart; // items to be purchased  private int numItems; // #items to be purchased   public Shopper() { cart = new Carryable[MAX_CART_ITEMS]; numItems = 0; } public Carryable[] getCart() { return cart; } public int getNumItems() { return numItems; } public String toString() { return "Shopper with shopping cart containing " + numItems + " items"; } // Return the total cost of the items in the cart  public float totalCost() { float total = 0; for (int i=0; ireturn total; } // Add an item to the shopper's shopping cart  public void addItem(Carryable g) { if (numItems // Removes the given item from the shopping cart  public void removeItem(Carryable g) { for (int i=0; iif (cart[i] == g) { cart[i] = cart[numItems - 1]; numItems -= 1; return; } } } // Go through the shopping cart and pack all packable items into bags  public void packBags() { GroceryBag[] packedBags = new GroceryBag[numItems]; int bagCount = 0; GroceryBag currentBag = new GroceryBag(); for (int i=0; iif (item.getWeight() if (!currentBag.canHold(item)) { packedBags[bagCount++] = currentBag; currentBag = new GroceryBag(); } currentBag.addItem(item); removeItem(item); i--; } } // Check this in case there were no bagged items  if (currentBag.getWeight() > 0) packedBags[bagCount++] = currentBag; // Now add the bags to the cart  for (int i=0; i// Display the contents of the cart  public void displayCartContents() { for (int i=0; i// Remoce and return all PerishableItems from the Shopping Cart  public PerishableItem[] removePerishables() { PerishableItem[] pItems = new PerishableItem[MAX_CART_ITEMS]; int pItemCount = 0; PerishableItem[] perishables; for (int i=0; iif (cart[i] instanceof GroceryBag) { perishables = ((GroceryBag) cart[i]).unpackPerishables(); for (int j=0; jelse { if (cart[i] instanceof PerishableItem) { pItems[pItemCount++] = (PerishableItem) cart[i]; removeItem(cart[i]); i--; } } } // Now create the proper size array  PerishableItem[] result = new PerishableItem[pItemCount]; for (int i=0; ireturn result; } // Return the amount of money that would be lost if the freezer breaks down  public float computeFreezerItemCost() { float total = 0; for (int i=0; iif (cart[i] instanceof GroceryBag) { GroceryItem[] itemsInBag = ((GroceryBag)cart[i]).getItems(); for (GroceryItem item: itemsInBag) { if (item instanceof FreezerItem) total += item.getPrice(); } } if (cart[i] instanceof FreezerItem) total += cart[i].getPrice(); } return total; } // Return the total cost of all items in the packed cart  public float computeTotalCost() { float total = 0; for (int i=0; ireturn total; } } 
public class ShopperTestProgram { public static void main(String args[]) { GroceryItem g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12, g13, g14, g15; g1 = new FreezerItem("Smart-Ones Frozen Entrees",1.99f,0.311f); g2 = new GroceryItem("SnackPack Pudding",0.99f,0.396f); g3 = new FreezerItem("Breyers Chocolate Icecream",2.99f,2.27f); g4 = new GroceryItem("Nabob Coffee",3.99f,0.326f); g5 = new GroceryItem("Gold Seal Salmon",1.99f,0.213f); g6 = new GroceryItem("Ocean Spray Cranberry Cocktail",2.99f,2.26f); g7 = new GroceryItem("Heinz Beans Original",0.79f,0.477f); g8 = new RefrigeratorItem("Lean Ground Beef",4.94f,0.75f); g9 = new FreezerItem("5-Alive Frozen Juice",0.75f,0.426f); g10 = new GroceryItem("Coca-Cola 12-pack",3.49f,5.112f); g11 = new GroceryItem("Toilet Paper - 48 pack",40.96f,10.89f); g12 = new RefrigeratorItem("2L Sealtest Milk",2.99f,2.06f); g13 = new RefrigeratorItem("Extra-Large Eggs",1.79f,0.77f); g14 = new RefrigeratorItem("Yoplait Yogurt 6-pack",4.74f,1.02f); g15 = new FreezerItem("Mega-Sized Chocolate Icecream",67.93f,15.03f); // Make a new customer and add some items to his/her shopping cart  Shopper c = new Shopper(); c.addItem(g1); c.addItem(g2); c.addItem(g3); c.addItem(g4); c.addItem(g5); c.addItem(g6); c.addItem(g7); c.addItem(g8); c.addItem(g9); c.addItem(g10); c.addItem(g1); c.addItem(g6); c.addItem(g2); c.addItem(g2); c.addItem(g3); c.addItem(g3); c.addItem(g3); c.addItem(g3); c.addItem(g3); c.addItem(g10); c.addItem(g11); c.addItem(g9); c.addItem(g5); c.addItem(g6); c.addItem(g7); c.addItem(g8); c.addItem(g8); c.addItem(g8); c.addItem(g5); c.addItem(g12); c.addItem(g13); c.addItem(g14); c.addItem(g15); System.out.println(" INITIAL CART CONTENTS:"); for (int i=0; i" " + c.getCart()[i]); } // Pack the bags and show the contents  c.packBags(); System.out.println(" CART CONTENTS:"); c.displayCartContents(); System.out.println(" REMAINING CART CONTENTS:"); for (int i=0; i" " + c.getCart()[i]); } System.out.println(" TOTAL FREEZER ITEM COST: $" + c.computeFreezerItemCost()); System.out.println(" TOTAL CART CONTENTS COST: $" + c.computeTotalCost()); System.out.println(" UNPACKING PERISHABLES:"); PerishableItem[] perishables = c.removePerishables(); for (int j=0; j" " + perishables[j]); } System.out.println(" REMAINING CART CONTENTS:"); c.displayCartContents(); } } 

Need to be solved in Java, thank you.

Course: COMP D 95-105/115 Assignmer x Home Chegg.com 06B C file://IC/Users/victor0323/Downloads/COMP1406 A5 W2017-Posted%20X1).pdf (2) When the Window First Opens When the window first opens, it should appear (1) with all buttons disabled, (2) the Products list populated with items, (3) the Shopping Cart and Contents lists should be empty and (4) the Total Price should appear as $0.00, aligned to the right side of the text field and property formatted. You MUST create an update0 method that properly adjusts the contents/view of each list, button and the text field whenever it is called. You should call this at the end of the constructor to populate a the window components. The array below should be used as the contents of the Products list. Grocery Item producta new Freezer Item Smart-Ones Frozen Entrees 1.99 0,311f new Grocery Item ("Snack Pack Pudding", 0.99f 0.396f r FreezerTtem Breyers Chocolate Icecream 2.99f, 2.27f new Grocery Item Nabob Coffee 3.99 0.326f new Grocery Item Gold Seal Salmon 1.99f, 0.213f new Grocery Item Ocean Spray Cranberry Cocktail 2.99f, 2.26f) new Grocery Item Heinz Beans original 0.79f 0.477f new Refrigerator Item Lean Ground Beef 4.94f 0.75f new Freezer Item Juice", 0.75f, 0.426f), 5-Al e F new Grocery Item Coca-Cola 12-pack 3. 19f, 5.1121 new Grocery Item let Paper 48 pack 40.96f, 10.89f Milk", 2.99f, 2.06f), Refrigerator Item 2L Sealtest new Refrigerator Item Extra-Large Eggs 1.79f, 0.77f new Refrigerator Item Yoplait Yogurt 6-pack 4.74 f, 1.02 f Freezer Item ("Mega-Sized Chocolate Icecream 67.93f, 15.03f a 459 NG 2017/2123 Course: COMP D 95-105/115 Assignmer x Home Chegg.com 06B C file://IC/Users/victor0323/Downloads/COMP1406 A5 W2017-Posted%20X1).pdf (2) When the Window First Opens When the window first opens, it should appear (1) with all buttons disabled, (2) the Products list populated with items, (3) the Shopping Cart and Contents lists should be empty and (4) the Total Price should appear as $0.00, aligned to the right side of the text field and property formatted. You MUST create an update0 method that properly adjusts the contents/view of each list, button and the text field whenever it is called. You should call this at the end of the constructor to populate a the window components. The array below should be used as the contents of the Products list. Grocery Item producta new Freezer Item Smart-Ones Frozen Entrees 1.99 0,311f new Grocery Item ("Snack Pack Pudding", 0.99f 0.396f r FreezerTtem Breyers Chocolate Icecream 2.99f, 2.27f new Grocery Item Nabob Coffee 3.99 0.326f new Grocery Item Gold Seal Salmon 1.99f, 0.213f new Grocery Item Ocean Spray Cranberry Cocktail 2.99f, 2.26f) new Grocery Item Heinz Beans original 0.79f 0.477f new Refrigerator Item Lean Ground Beef 4.94f 0.75f new Freezer Item Juice", 0.75f, 0.426f), 5-Al e F new Grocery Item Coca-Cola 12-pack 3. 19f, 5.1121 new Grocery Item let Paper 48 pack 40.96f, 10.89f Milk", 2.99f, 2.06f), Refrigerator Item 2L Sealtest new Refrigerator Item Extra-Large Eggs 1.79f, 0.77f new Refrigerator Item Yoplait Yogurt 6-pack 4.74 f, 1.02 f Freezer Item ("Mega-Sized Chocolate Icecream 67.93f, 15.03f a 459 NG 2017/2123

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!