Solution with base structures in Java