Purse1

Purse1 - @return output the string representation of coins...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.ArrayList; i /** A purse holds a collection of coins. */ public class Purse1 { /** instance variables */ private ArrayList<String> coins; /** Constructs an empty purse. */ public Purse1() { coins = new ArrayList<String>(); } /** Add a coin to the purse. @param coinName the coin to add */ public void addCoin(String coinName) { coins.add(coinName); } /** Displays the string representation of the object.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: @return output the string representation of coins */ public String toString() { if (coins.size() == 0) return "Purse"; String output = "Purse["; for (int i = 0; i < coins.size(); i++) { output = output + coins.get(i) + ","; } output = output.substring(0, output.length() - 1); // remove the last "," return output + "]"; } }...
View Full Document

This note was uploaded on 06/07/2010 for the course CS 201 taught by Professor Staff during the Spring '08 term at Iona.

Ask a homework question - tutors are online