In java use the provided code to write a Java program that: – Uses StringArrayBag to store your five favorite foods prom
Posted: Sun Jul 03, 2022 11:23 am
In java use the provided code to write a Java program that:–
Uses StringArrayBag to store your five favorite foods
prompt the user to enter their favorite foods or you canhard
Removes and prints the foods one-by-one until the bag isempty
public interface StringBagInterface { /** * Adds item to bag * @param item Item to be added to bag * @return If true, item was successfullyadded */ boolean add(String item); /** * Removes all items from bag */ void clear(); /** * Determines if specified item is stored inbag * @param item Item to check for in bag * @return If true, item is in bag */ boolean contains(String item); /** * Count instances of specified item inbag * @param item Item to be counted * @return Count for specified item */ int countOf(String item); /** * Determines if items are stored in bag * @return If true, no items are in bag */ boolean isEmpty(); /** * Remove and return one item from bag * @return Removed item, or null if nothing canbe removed */ String remove(); /** * Remove specific item from bag * @param item Item to be removed * @return If true, item was successfullyremoved */ boolean remove(String item); /** * Gets number of items stored in bag * @return Number of items in bag */ int size(); /** * Exports contents of bag as an array * @return Array with items from bag */ String[] toArray();}
Uses StringArrayBag to store your five favorite foods
prompt the user to enter their favorite foods or you canhard
Removes and prints the foods one-by-one until the bag isempty
public interface StringBagInterface { /** * Adds item to bag * @param item Item to be added to bag * @return If true, item was successfullyadded */ boolean add(String item); /** * Removes all items from bag */ void clear(); /** * Determines if specified item is stored inbag * @param item Item to check for in bag * @return If true, item is in bag */ boolean contains(String item); /** * Count instances of specified item inbag * @param item Item to be counted * @return Count for specified item */ int countOf(String item); /** * Determines if items are stored in bag * @return If true, no items are in bag */ boolean isEmpty(); /** * Remove and return one item from bag * @return Removed item, or null if nothing canbe removed */ String remove(); /** * Remove specific item from bag * @param item Item to be removed * @return If true, item was successfullyremoved */ boolean remove(String item); /** * Gets number of items stored in bag * @return Number of items in bag */ int size(); /** * Exports contents of bag as an array * @return Array with items from bag */ String[] toArray();}