import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.lang.*; import java.util.*; public class Pile { private Vector chips = new Vector(); //elements will be of class PokerChip private int size = 0; private int totalValue = 0; public Pile() { } public Pile (Color color, int initSize, int faceValue) { for (int i=0; i 0) toWhichPile.addChip (this.removeTop()); } public int getSize() { return size; } public int getValue() { return totalValue; } public void addChip(PokerChip chip) { size++; totalValue += chip.getValue(); chips.addElement(chip); } public PokerChip removeTop() { PokerChip chip = (PokerChip)chips.elementAt(size-1); chips.removeElementAt(size-1); totalValue = totalValue - chip.getValue(); size--; return chip; } public void returnAllChips(Pile redPile, Pile bluePile, Pile greenPile) { PokerChip chip; while (size > 0) { chip = this.removeTop(); if (chip.getColor() == Color.red) redPile.addChip(chip); if (chip.getColor() == Color.blue) bluePile.addChip(chip); if (chip.getColor() == Color.green) greenPile.addChip(chip); } } // This method is explicitly called when an object wants a pile to // paint itself. See the applet's paint(). public void paint(Graphics g, int startingX, int startingY) { PokerChip chip; int x = startingX; int y = startingY; Enumeration elements = chips.elements(); g.drawString("Total = " + this.getValue(), startingX-15, startingY-5); if (size == 0) return; for (Enumeration e = chips.elements() ; e.hasMoreElements() ;) { chip = (PokerChip) e.nextElement(); chip.paint(g, x, y); y = y + 30; } } }