Question
You are to use the set of codes provided to complete the implementation of the Bags as seen in lecture. Some of the pieces of
You are to use the set of codes provided to complete the implementation of the Bags as seen in lecture. Some of the pieces of information missing should be designed appropriately to obtain the outputs as indicated. The completed source code files should be submitted in the dropbox Lab # 5 part a Output:
Sunflower seeds $12.95
Bird bath $44.99
Squirrel guard $15.47
Bird feeder $20.50
Total cost: $93.91
Items : Item [] items = {new Item ("Bird feeder", 2050),
new Item ("Squirrel guard", 1547),
new Item ("Bird bath", 4499),
new Item ("Sunflower seeds", 1295) };
BagInterface:
/** LISTING 1-1 An interface that describes the operations of a bag of objects. @author Frank M. Carrano @version 3.0 */ public interface BagInterface
/** 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. @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 locate @return true if this bag contains anEntry, or false otherwise */ 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 */ public T[] toArray();
/** Creates a new bag that combines the contents of this bag and anotherBag. @param anotherBag the bag that is to be added @return a combined bag */ // public BagInterface union(BagInterface anotherBag);
/** Creates a new bag that contains those objects that occur in both this bag and anotherBag. @param anotherBag the bag that is to be compared @return a combined bag */ // public BagInterface intersection(BagInterface anotherBag);
/** Creates a new bag of objects that would be left in this bag after removing those that also occur in anotherBag. @param anotherBag the bag that is to be removed @return a combined bag */ // public BagInterface difference(BagInterface anotherBag); } // end BagInterface
Bag:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package shopping;
/** * * @author apple */ public class Bag Shopping: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package shopping; /** * * @author apple */ public class Shopping { /** * @param args the command line arguments */ 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 < item > shoppingCart =new Bag
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