Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
[ch08] 8.3 property usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhsim86 committed May 27, 2017
1 parent f19145a commit e422e93
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/main/java/exam/test05/Score.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package exam.test05;

/**
* Created by nhnent on 2017. 5. 27..
*/
public class Score {

private String name;
private float kor;
private float eng;
private float math;

public Score() {

}

public Score(String name, float kor, float eng, float math) {
this.name = name;
this.kor = kor;
this.eng = eng;
this.math = math;
}

public float average() {
return sum() / (float)3;
}

public float sum() {
return kor + eng + math;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public float getKor() {
return kor;
}

public void setKor(float kor) {
this.kor = kor;
}

public float getEng() {
return eng;
}

public void setEng(float eng) {
this.eng = eng;
}

public float getMath() {
return math;
}

public void setMath(float math) {
this.math = math;
}

@Override
public String toString() {
return name + ", " + kor + ", " + eng + ", " + math;
}
}
17 changes: 17 additions & 0 deletions src/main/java/exam/test05/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package exam.test05;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* Created by nhnent on 2017. 5. 27..
*/
public class Test {

public static void main(String[] args) {

ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("file:/Users/nhnent/workspace/workspace-intellij/java_webdev_workbook_spring/src/main/java/exam/test05/beans.xml");

System.out.println(ctx.getBean("score1"));
System.out.println(ctx.getBean("score2"));
}
}
28 changes: 28 additions & 0 deletions src/main/java/exam/test05/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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="score1" class="exam.test05.Score">
<property name="name">
<value>Hong Gildong</value>
</property>
<property name="kor">
<value>100</value>
</property>
<property name="eng">
<value>95</value>
</property>
<property name="math">
<value>90</value>
</property>
</bean>

<bean id="score2" class="exam.test05.Score">
<property name="name" value="Lim Gukkjeon" />
<property name="kor" value="85" />
<property name="eng" value="99" />
<property name="math" value="100" />
</bean>
</beans>

0 comments on commit e422e93

Please sign in to comment.