implemented ACM-Rails-514 using Java's built-in stack