http://www.kgeorgiy.info/courses/java-advanced/homeworks.html#homework-6