sungjuk.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <?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"> <!-- CalculatorService7 객체를 생성 --> <bean id="calc" class="com.spring.springTest.t0601.SungjukService" /> <!-- CalculatorVO7 객체를 생성 --> <bean id="vo" class="com.spring.springTest.t0601.SungjukVO"> <property name="name" value="철수"/> <property name="kor" value="100"/> <property name="eng" value="80"/> <property name="mat" value="70"/> <property name="service"> <ref bean="calc"/> </property> </bean> <bean id="vo2" class="com.spring.springTest.t0601.SungjukVO"> <property name="name" value="영희"/> <property name="kor" value="90"/> <property name="eng" value="80"/> <property name="mat" value="100"/> </bean> <bean id="vo3" class="com.spring.springTest.t0601.SungjukVO"> <property name="name" value="하늘"/> <property name="kor" value="60"/> <property name="eng" value="80"/> <property name="mat" value="70"/> </bean> </beans> | cs |
SungjukVO
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | package com.spring.springTest.t0601; public class SungjukVO { private String name; private int kor; private int eng; private int mat; private SungjukService service = new SungjukService(); private SungjukService2 service2 = new SungjukService2(); public String getName() { return name; } public void setName(String name) { this.name = name; } public int getKor() { return kor; } public void setKor(int kor) { this.kor = kor; } public int getEng() { return eng; } public void setEng(int eng) { this.eng = eng; } public int getMat() { return mat; } public void setMat(int mat) { this.mat = mat; } public SungjukService getService() { return service; } public void setService(SungjukService service) { this.service = service; } public void info() { service.info(name,kor,eng,mat); } public void tot() { service.tot(kor,eng,mat); } public void avg() { service.avg(kor,eng,mat); } public void gread() { service.gread(kor,eng,mat); } public int tott() { return service.tott(kor,eng,mat); } public void rank() { service2.rank(name,kor,eng,mat); } } | cs |
SungjukService
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | package com.spring.springTest.t0601; public class SungjukService { public void tot(int kor, int eng, int mat) { System.out.print(" " +(kor+eng+mat)); } public void avg(int kor, int eng, int mat) { System.out.print(" " + (kor+eng+mat)/3 + " "); } public void info(String name, int kor, int eng, int mat) { System.out.print(name + " " +kor + " " +eng + " " +mat); } public void gread(int kor, int eng, int mat) { int gread = ((kor+eng+mat)/3); if(gread > 90) { System.out.print("A학점"); } else if(gread > 80) { System.out.print("B학점"); } else if(gread > 70) { System.out.print("C학점"); } else if(gread > 60) { System.out.print("D학점"); } else if(gread > 50) { System.out.print("F학점"); } } public int tott(int kor, int eng, int mat) { int tott = kor+eng+mat; return tott; } } | cs |
SungjukService2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | package com.spring.springTest.t0601; public class SungjukService2 { int[][] test = new int[2][3]; int cnt=0; public void rank(String name, int kor, int eng, int mat) { int tot = (kor+eng+mat); test[0][cnt] = tot; test[1][cnt] = 1; cnt++; System.out.println("asa"+cnt); if(cnt == 3) { System.out.println("qwer"); if(test[0][0] > test[0][1]) { test[1][1] += 1; } if(test[0][0] > test[0][2]) { test[1][2] += 1; } if(test[0][1] > test[0][2]) { test[1][2] += 1; } for(int i=0;i<3;i++) { System.out.println(test[1][i]); } } } } | cs |
SungjukRun
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | package com.spring.springTest.t0601; import org.springframework.context.support.ClassPathXmlApplicationContext; /* 성적계산 : 성명/국어/영어/수학 점수를 xml을 통해서 입력받아 setter값을 주입하여 '총점/평균/학점'을 계산하는 프로그램을 작성(3명(철수,영희,하늘)의 자료를 주입한다. 과제 : 순위를 구하여 아래와 같이 출력하시오. ===================================== 성명 국어 영어 수학 총점 평균 학점 순위 ------------------------------------- 철수 100 80 70 250 83.3 B학점 2등 영희 90 80 100 270 90.0 A학점 1등 하늘 60 80 70 210 70.0 C학점 3등 ====================================== */ /* SungjukVO : SungjukService : sungjuk.xml : CalcVO : 총점, 평균, 학점 */ public class SungjukRun { public static void main(String[] args) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("xml/sungjuk.xml"); SungjukVO vo = (SungjukVO) ctx.getBean("vo"); SungjukVO vo2 = (SungjukVO) ctx.getBean("vo2"); SungjukVO vo3 = (SungjukVO) ctx.getBean("vo3"); vo.rank(); vo2.rank(); vo3.rank(); System.out.println("====================================="); System.out.println("성명 국어 영어 수학 총점 평균 학점 순위"); System.out.println("-------------------------------------"); vo.info(); vo.tot(); vo.avg(); vo.gread(); System.out.println(); System.out.println("-------------------------------------"); vo2.info(); vo2.tot(); vo2.avg(); vo2.gread(); System.out.println(); System.out.println("-------------------------------------"); vo3.info(); vo3.tot(); vo3.avg(); vo3.gread(); System.out.println(); System.out.println("-------------------------------------"); ctx.close(); } } | cs |
service2를 따로 만들어 service2안에 값들을 배열로 누적시켜 랭크를 구해보려 했지만 값들마다 new로 계속 객체가 생성된다는 것들 인지하지 못하여 값들이 누적이 안 되었습니다 더 생각해 보려고 해도 잘 모르겠어서 실패한 상태로 올려봅니다 ㅠㅠ