//Tony Piechowski
package purse;
import java.util.ArrayList;
public class Purse {
    private ArrayList<String> al;
    private String s;
   
    public Purse() {
        al = new ArrayList<String> ();
    }
    public String toString() {
        StringBuffer b = new StringBuffer();
       
        b.append("purse[");
        for (String e : al) {
            b.append(e + ",");
        }
        b.append ("]");
        return b.toString();
        }
    public void reverse(){
        ArrayList<String> l = new ArrayList<String>();
       
        for (int x = al.size() -1; x >= 0; x--){
            l.add(al.get(x));
           
            al = (ArrayList<String>)l.clone();
        }
    }
    public ArrayList<String> getCoins(){
        return al;
    }
    public void empty(){
        al.clear();
    }
    public void addCoin(String s){
        al.add(s);
    }
   
    public void transfer(Purse other){
        for (String s : other.getCoins()){
            al.add(s);
        }
        other.empty();
    }
   
    public boolean isEmpty(){
        if (al.size() == 0){
            return true;
        }
        else {
            return false;
        }
    }
    public boolean sameCoins(Purse other){
        if (toString().equals(other.toString()) == true){
            return true;
        }
        else{
            return false;
        }
    }
    public boolean sameContents(Purse other){
        ArrayList<String> list1 = (ArrayList<String>)other.getCoins().clone();
       
        if (list1.size() < 1){
            return false;
        }
        else{
        }
        boolean found = false;
        if (isEmpty() == true && other.isEmpty() == true){
            return true;
        }
        for (String coin : al){
            for (int x = 0; x < list1.size() && found == false; x++){
               
                if (coin.equals(list1.get(x)) == true) {
                    found = true;
                    list1.remove (x);
                }
            }
           found = false;
        }
        if (list1.size() == 0){
            return true;
        }
        else {
            return false;
        }
    }
    public static void main(String[] args) {
        Purse p1 = new Purse();
        Purse p2 = new Purse();
        Purse p3 = new Purse();
       
        p1.addCoin("nickle");
        p1.addCoin("penny");
        p1.addCoin("dime");
       
        p2.addCoin("nickle");
        p2.addCoin("penny");
        p2.addCoin("dime");
       
        p1.reverse();
        System.out.println(p1.sameContents(p2));
        System.out.println(p1.sameCoins(p2));
    }
}
This site is powered by the Northwoods Titan Content Management System