성별, 체질량 지수, 허리둘레의 값을 받으면, '진단' 텍스트를 반환해야하는 일이 생겼다.
Result checkRecentStatus(int gender, double bmi, double abdomen) {
if (gender == Gender.male.index) {
return Result.measureError;
}
if (bmi < 18.6) {
if (abdomen >= 80) {
return Result.lessAndAbdomenOver;
}
return Result.lessWeight;
}
if (bmi > 18.5 && bmi < 23) {
if (abdomen >= 85) {
return Result.normalAndAbdomenOver;
}
return Result.normalWeight;
}
if (bmi >= 23 && bmi < 25) {
if (abdomen >= 85) {
return Result.overAndAbdomenOver;
}
return Result.overWeight;
}
if (bmi >= 25 && bmi < 30) {
if (abdomen >= 85) {
return Result.firstObesityAndAbdomenOver;
}
return Result.firstObesity;
}
if (bmi >= 30 && bmi < 35) {
if (abdomen >= 85) {
return Result.secondObesityAndAbdomenOver;
}
return Result.secondObesity;
}
return Result.highObesity;
}
bool isOverAbdomen(double bmi, double abdomen) {
if(abdomen >= 85) {
return true;
} else if(bmi < 18.5 && abdomen >= 80) {
return true;
}
return false;
}
int showIntStatus(double bmi, double abdomen) {
int resultIndex = Result.lessWeight.index;
List list = [18.5, 23, 25, 30, 35];
for(var x in list) {
if(bmi < x) {
return isOverAbdomen(bmi, abdomen) ? resultIndex + 1 : resultIndex;
}
resultIndex = resultIndex + 2;
}
return resultIndex;
}
enum Result {
measureError,
lessWeight,
lessAndAbdomenOver,
normalWeight,
normalAndAbdomenOver,
overWeight,
overAndAbdomenOver,
firstObesity,
firstObesityAndAbdomenOver,
secondObesity,
secondObesityAndAbdomenOver,
highObesity,
}
이보다 더 좋은 리펙토링이 분명 있겠지?
그래서 끊임없이 공부가 필요하다 ㅜㅜ