Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Implement a class Purse. A purse contains a collection of coins. For simplici

ID: 3655943 • Letter: 1

Question

1) Implement a class Purse. A purse contains a collection of coins. For simplicity, we will only store the coin names in an ArrayList. Supply a method void addCoin(String coinName) Add a method toString to the Purse class that returns a string showing the coins in the purse in the format Purse[Quarter, Dime, Nickel, Dime] 2) Add a method to your Purse class that returns a true value if a particular type of coin is in the purse, and returns false otherwise. The method is passed in a string representing the coin to be found: public boolean findCoin(String coin)

Explanation / Answer

import java.util.ArrayList; /** A purse holds a collection of coins. */ public class Purse { /** Constructs an empty purse. */ public Purse() { coins = new ArrayList(); } /** Adds a coin to the purse. @param coinName the coin to add */ public void addCoin(String coinName) { . . . } /** Returns a string describing the object. @return a string in the format "Purse[coinName1,coinName2,...]" */ public String toString() { . . . } private ArrayList coins; }