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 contructor-args usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dhsim86 committed May 27, 2017
1 parent fb201d0 commit f19145a
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/main/java/exam/test04/Score.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package exam.test04;

/**
* 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;
}
}
20 changes: 20 additions & 0 deletions src/main/java/exam/test04/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package exam.test04;

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/test04/beans.xml");

System.out.println(ctx.getBean("score1"));
System.out.println(ctx.getBean("score2"));
System.out.println(ctx.getBean("score3"));
System.out.println(ctx.getBean("score4"));
System.out.println(ctx.getBean("score5"));
}
}
57 changes: 57 additions & 0 deletions src/main/java/exam/test04/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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.test04.Score">
<constructor-arg>
<value type="java.lang.String">Hong Gildong</value>
</constructor-arg>
<constructor-arg>
<value type="float">91</value>
</constructor-arg>
<constructor-arg>
<value type="float">92</value>
</constructor-arg>
<constructor-arg>
<value type="float">93</value>
</constructor-arg>
</bean>

<bean id="score2" class="exam.test04.Score">
<constructor-arg>
<value>Lim Gukkjeong</value>
</constructor-arg>
<constructor-arg>
<value>81</value>
</constructor-arg>
<constructor-arg>
<value>82</value>
</constructor-arg>
<constructor-arg>
<value>83</value>
</constructor-arg>
</bean>

<bean id="score3" class="exam.test04.Score">
<constructor-arg type="java.lang.String" value="Gang Bogo" />
<constructor-arg type="float" value="71" />
<constructor-arg type="float" value="72" />
<constructor-arg type="float" value="73" />
</bean>

<bean id="score4" class="exam.test04.Score">
<constructor-arg value="Lee Sunsin" />
<constructor-arg value="61" />
<constructor-arg value="62" />
<constructor-arg value="63" />
</bean>

<bean id="score5" class="exam.test04.Score">
<constructor-arg value="53" index="3" />
<constructor-arg value="51" index="1" />
<constructor-arg value="Gang Gamchan" index="0" />
<constructor-arg value="52" index="2"/>
</bean>
</beans>

0 comments on commit f19145a

Please sign in to comment.