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

Implement a class Purse. A purse contains a collection of coins. For simplicity,

ID: 3640100 • Letter: I

Question

Implement a class Purse. A purse contains a collection of coins. For simplicity, we will only store the coin names in an ArrayList<String>. 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

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; }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote