gross messy java solution