Second task. Java implementation with Parameterized class