public class StackMachine extends IntStack { /** * Pop the two top integers from the stack, add * them, and push their integer sum. * @throws EmptyStack if stack runs out */ public void add() throws EmptyStack { int i = pop(); int j = pop(); push(i + j); } /** * Pop the two top integers from the stack, divide * them, and push their integer quotient. * @throws EmptyStack if stack runs out */ public void divide() throws EmptyStack { int i = pop(); int j = pop(); push(i / j); } /** * Pop the two top integers from the stack, multiply * them, and push their integer product. * @throws EmptyStack if stack runs out */ public void multiply() throws EmptyStack { int i = pop(); int j = pop(); push(i * j); } /** * Pop the two top integers from the stack, subtract * the second from the first, and push their integer * difference. * @throws EmptyStack if stack runs out */ public void subtract() throws EmptyStack { int i = pop(); int j = pop(); push(i - j); } }