import java.util.Stack; import Card; /* Note: Inherits operations from stack class. Overrides the push operation to provide a stack that will only accept cards in order. */ public class BuildStack extends Stack { public boolean push (Card item) /* Function: Compares arguement card to the top card of the stack. If the card is one greater than the top card, then it is pushed onto the stack. Otherwise the card is not pushed onto the stack. Accepts: A card. Returns: A boolean value representing the success or failure of the push operation. */ { Card temp = new Card (); Object object = new Object (); if (empty ()) { temp.setUseValue (0); //if stack is empty then look for an ace } else { object = this.peek (); temp = (Card) object; //cast object into a card } if (item.showUseValue() == 14) { if (temp.showUseValue() == 13) return false; else item.setUseValue(temp.showUseValue() + 1); } if (temp.showUseValue () + 1 == item.showUseValue ()) { super.push (item); //Call to superclass Push operation return true; } return false; } }