BMICalculator
package com.javalec.ex;
public class BMICalculator {
private double lowWeight;
private double normal;
private double overWeight;
private double obesity;
public void bmicalculator(double weight, double height) {
double h = height * 0.001;
double result = weight / (h*h);
System.out.println("BMI 지수:" + (int)result);
if(result > obesity) {
System.out.println("비만 입니다.");
} else if(result > overWeight) {
System.out.println("과체중 입니다.");
} else if(result > normal) {
System.out.println("정상 입니다.");
} else {
System.out.println("저체중 입니다.");
}
MainClass
package com.javalec.ex;
import org.springframework.context.support.AbstractApplicationContext;
import.org.springframework.context.support.GenericXmlApplicationContext;
public class MainClass{
String configLocation = "classpath:applicationCTX.xml";
AbstractApplicationContext ctx = new GenericXmlApplicationContext();
MyInfo myInfo = ctx.getBean("myInfo",MyInfo.class);
myInfo.getInfo();
ctx.close();
}
MyInfo
package com.javalec.ex;
import java.util.ArrayList;
public class MyInfo {
private String name;
private double height;
private double weight;
private ArrayList<String> hobbys;
private BMICalculator bmiCalculator;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public ArrayList<String> getHobbys() {
return hobbys;
}
public void setHobbys(ArrayList<String> hobbys) {
this.hobbys = hobbys;
}
public BMICalculator getBmiCalculator() {
return bmiCalculator;
}
public void setBmiCalculator(BMICalculator bmiCalculator) {
this.bmiCalculator = bmiCalculator;
}
public void bmiCalculation() {
bmiCalculator.bmicalculation(weight, height);
}
public void getInfo() {
System.out.println("이름 : " + name);
System.out.println("키 : " + height);
System.out.println("몸뭄게 : " + weight);
System.out.println("취미 : " + hobbys);
bmiCalculation();
}
}