/* Body Mass Index * 1. 표준체중 * ( 키 - 100 ) * 0.92 * * 2. 비만도 * ( 실제체중 / 표준체중 ) * 100 * * 3. 평가 * 110 ~ 120 과체중 * 120 ~ 129 비만 * 130 ~ 고도비만 * * Input prams * 1. 키 * 2. 몸무게 * 3. 이름 * * Output Data * ------------------------------------------------------------------------ * BMI Calculator * made by Leezzang * ------------------------------------------------------------------------ * 성 명 : 홍길동 * 신 장 : 172cm * 체 중 : 68kg * 위의 정보로 계산되어진 결과입니다. * ------------------------------------------------------------------------ * 표준체중 : ???kg * 비만지수 : ???% * 결 과 : * ------------------------------------------------------------------------- */
> BMI.java ( 파일 생성 )
package bmi;
public class BMI {
public static void main(String [] args) { // Controller String N = args[0];
String height = args[1]; String weight = args[2];
★ string 값을 int 타입으로 변환
int he =Integer.parseInt(args[1]); //args[1]을 int로 형변환후 he 변수 지정 int we = Integer.parseInt(args[2]); //args[2]을 int로 형변환후 we 변수 지정
BMI_Calc bc = new BMI_Calc(); // BMI_Calc 호출 bc.Data(he, we); int sw = bc.StandardW(); int bmi = bc.bmi(sw); String result = bc.Result(bmi); Output ot = new Output(); ot.output(N, he, we, sw, bmi, result); } }
BMI_Calc.java ( 파일 생성 )
package bmi; public class BMI_Calc { private int h,w; //인스턴스 변수 선언 // params 저장 public void Data(int height,int weight){ h = height; //현재 배열안에 172 w = weight; //현재 배열안에 68 }
// 표준 체중 계산 메서드 public int StandardW() { int sw = (h - 100) * 92 / 100; int mod = (h - w) * 9 % 10; sw = ( mod >= 5 )? sw + 1 : sw; return sw; // void 는 실행만하고 끝나며 int를 넣을경우 결과값을 리턴해줘야만한다. }
// 비만도 계산 메소드 public int bmi(int sw) { int bmi = (w / sw) * 100; return bmi; } // 결과값 출력 메소드 ( Result ) public String Result(int bmi){ String result; if (bmi >= 130) { result = "고도비만"; } else if (bmi >= 120){ result = "비만"; } else if (bmi >= 110) { result = "과체중"; } else { result = "표준체중"; } return result; } }
> Output.java ( 파일 생성 )
package bmi; public class Output { public void output(String Name,int he,int we,int sw,int bmi,String result){ System.out.println(" "+"Outout Data"); System.out.println("----------------------------------------------------"); System.out.println(" "+"BMI Calculator"); System.out.println(" "+"made by Leezzang"); System.out.println("----------------------------------------------------"); System.out.println("성 명 : "+Name); System.out.println("신 장 : "+he+"cm"); System.out.println("체 중 : "+we+"kg"); System.out.println(" "+"위의 정보는 계산 되어진 결과입니다"+" "); System.out.println("----------------------------------------------------"); System.out.println("표준체중 : "+sw+"kg"); System.out.println("비만지수 : "+bmi+"kg"); System.out.println("결 과 : "+result); System.out.println("----------------------------------------------------"); } }