complete java solution