Java code for the last part of the project.