obesity) { System.out.println("비만입니다."); } else if (result > overweight) { System.out.println("과체중입니다."); } else if (result > normal) { System.out.println("정상입니다."); } else { System.out.println("저체중입니다."); } } public double getLowweight() { return lowweight; } public void setLowweight(double lowweight) { this.lowweight = lowweight; } public double getNormal() { return normal; } public void setNormal(double normal) { this.normal = normal; } public double getOverweight() { return overweight; } public void setOverweight(double overweight) { this.overweight = overweight; } public double getO"> obesity) { System.out.println("비만입니다."); } else if (result > overweight) { System.out.println("과체중입니다."); } else if (result > normal) { System.out.println("정상입니다."); } else { System.out.println("저체중입니다."); } } public double getLowweight() { return lowweight; } public void setLowweight(double lowweight) { this.lowweight = lowweight; } public double getNormal() { return normal; } public void setNormal(double normal) { this.normal = normal; } public double getOverweight() { return overweight; } public void setOverweight(double overweight) { this.overweight = overweight; } public double getO"> obesity) { System.out.println("비만입니다."); } else if (result > overweight) { System.out.println("과체중입니다."); } else if (result > normal) { System.out.println("정상입니다."); } else { System.out.println("저체중입니다."); } } public double getLowweight() { return lowweight; } public void setLowweight(double lowweight) { this.lowweight = lowweight; } public double getNormal() { return normal; } public void setNormal(double normal) { this.normal = normal; } public double getOverweight() { return overweight; } public void setOverweight(double overweight) { this.overweight = overweight; } public double getO">
package com.lgy.spring4_1;

public class BMICalculator {
	private double lowweight;
	private double normal;
	private double overweight;
	private double obesity;

	public void bmiCalculation(double weight, double height) {
		double h = height * 0.01;
		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("저체중입니다.");
		}
	}

	public double getLowweight() {
		return lowweight;
	}

	public void setLowweight(double lowweight) {
		this.lowweight = lowweight;
	}

	public double getNormal() {
		return normal;
	}

	public void setNormal(double normal) {
		this.normal = normal;
	}

	public double getOverweight() {
		return overweight;
	}

	public void setOverweight(double overweight) {
		this.overweight = overweight;
	}

	public double getObesity() {
		return obesity;
	}

	public void setObesity(double obesity) {
		this.obesity = obesity;
	}

}
package com.lgy.spring4_1;

import java.util.ArrayList;

public class MyInfo {
	private String name;
	private double height;
	private double weight;
	private ArrayList<String> hobbys;
	private 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();
	}
	
	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;
	}
	
	
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="<http://www.springframework.org/schema/beans>"
	xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>"
	xsi:schemaLocation="<http://www.springframework.org/schema/beans> <http://www.springframework.org/schema/beans/spring-beans.xsd>">
	<bean id="bmiCalculator" class="com.lgy.spring4_1.BMICalculator">
		<property name="lowweight">
			<value>18.5</value>
		</property>

		<property name="normal">
			<value>23.5</value>
		</property>

		<property name="overweight">
			<value>25</value>
		</property>
		<property name="obesity">
			<value>30</value>
		</property>
	</bean>
	<bean id="myInfo" class="com.lgy.spring4_1.MyInfo">
		<property name="name">
			<value>홍길동</value>
		</property>
		<property name="height">
			<value>187</value>
		</property>
		<property name="weight">
			<value>84</value>
		</property>

		<property name="hobbys">
			<list>
				<value>수영</value>
				<value>요리</value>
				<value>독서</value>
			</list>
		</property>
		<property name="bmiCalculator">
			<ref bean="bmiCalculator"></ref>
		</property>
	</bean>
</beans>
package com.lgy.spring4_1;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

public class MainCalculator {
	public static void main(String[] args) {
		String configloc = "classpath:applicationCTX.xml";
		AbstractApplicationContext ctx = new GenericXmlApplicationContext(configloc);
		MyInfo myInfo = ctx.getBean("myInfo",MyInfo.class);
		
		myInfo.getInfo();
	}
}

20230519120912.png