public void moveRing(int from, int to) throws IllegalMovementException { try { if (from == to) { throw new IllegalMovementException("Move ring to another tower!", "違う塔にリングを移しましょうよ。"); } if ((!tower[to].empty() && (((Integer)tower[from].peek()).intValue() > ((Integer)tower[to].peek()).intValue()))) { throw new IllegalMovementException("Can't move bigger ring upto smaller ring!", "小さなりリングの上に大きなリングを動かすことはできません。"); } tower[to].push(tower[from].pop()); // from の一番上のリングを to にのせる。 } catch (java.util.EmptyStackException e) { throw new IllegalMovementException("There is no ring in tower " + from + " !", "その塔にリングはありません。"); } }