Question: Follow the following two java.class. creates the new java (ArrayBag.java and item.java) that drives them public interface BagInterface { /** Gets the current number of
Follow the following two java.class. creates the new java (ArrayBag.java and item.java) that drives them
public interface BagInterface { /** Gets the current number of entries in this bag. @return The integer number of entries currently in the bag. */ public int getCurrentSize(); /** Sees whether this bag is empty. @return True if the bag is empty, or false if not. */ public boolean isEmpty(); /** Adds a new entry to this bag. @param newEntry The object to be added as a new entry. @return True if the addition is successful, or false if not. */ public boolean add(T newEntry); /** Removes one unspecified entry from this bag, if possible. @return Either the removed entry, if the removal. was successful, or null. */ public T remove(); /** Removes one occurrence of a given entry from this bag, if possible. @param anEntry The entry to be removed. @return True if the removal was successful, or false if not. */ public boolean remove(T anEntry); /** Removes all entries from this bag. */ public void clear(); /** Counts the number of times a given entry appears in this bag. @param anEntry The entry to be counted. @return The number of times anEntry appears in the bag. */ public int getFrequencyOf(T anEntry); /** Tests whether this bag contains a given entry. @param anEntry The entry to find. @return True if the bag contains anEntry, or false if not. */ public boolean contains(T anEntry); /** Retrieves all entries that are in this bag. @return A newly allocated array of all the entries in the bag. Note: If the bag is empty, the returned array is empty. */ public T[] toArray(); } // end BagInterface
package shopping_cart; public class OnlineShopper { public static void main(String[] args) { Item[] items = {new Item("Bird feeder", 2050), new Item("Squirrel guard", 1547), new Item("Bird bath", 4499), new Item("Sunflower seeds", 1295)}; BagInterface shoppingCart = new ArrayBag<>(); int totalCost = 0; // Statements that add selected items to the shopping cart: for (int index = 0; index < items.length; index++) { Item nextItem = items[index]; // Simulate getting item from shopper shoppingCart.add(nextItem); totalCost = totalCost + nextItem.getPrice(); } // end for // Simulate checkout while (!shoppingCart.isEmpty()) System.out.println(shoppingCart.remove()); System.out.println("Total cost: " + "t$" + totalCost / 100 + "." + totalCost % 100); } // end main } // end OnlineShopper /* Sunflower seeds $12.95 Bird bath $44.99 Squirrel guard $15.47 Bird feeder $20.50 Total cost: $93.91 */ When you have completed the above java, please answer the following questions. thanks
- What have you learned by completing the coding?
- What challenges did you encounter, if any?
- Anything else you would like to share?
- addition, ask a probingquestion (or two) to consider.
Step by Step Solution
3.49 Rating (169 Votes )
There are 3 Steps involved in it
To complete the coding based on the provided Java interfaces and classes we need to create two new Java files ArrayBagjava and Itemjava ArrayBagjava p... View full answer
Get step-by-step solutions from verified subject matter experts
