일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 단축키
- angular2
- 전체텍스트
- Validations
- 추상클래스
- 페이징
- 업캐스팅
- jquery
- 야구게임
- 전자정부
- 스프링
- while
- 상속
- 다형성
- 이클립스
- IBatis procedure
- Login with OAuth Authentication
- 전체
- 로또
- 형변환
- Full text
- 다운캐스팅
- 25가지 효율적인 sql작성법
- 자바 야구게임
- 상속예제
- 가변인자
- Random
- full text indexing
- 자바
Archives
- Today
- Total
nalaolla
Method 예제 2 (Score) 본문
728x90
반응형
- package test.com;
- public class Test02ScoreDAO {
- public String insert(Test02ScoreVO vo) {
- System.out.println(vo);
- System.out.println("데이터 저장 처리 완료");
- System.out.println(vo.getName());
- System.out.println(vo.getKor());
- System.out.println(vo.getEng());
- System.out.println(vo.getMath());
- System.out.println(vo.getTotal());
- System.out.println(vo.getAvg());
- System.out.println(vo.getGrade());
- return "success..";
- }
- public String update(Test02ScoreVO vo) {
- System.out.println(vo);
- System.out.println("데이터 수정 처리 완료");
- System.out.println(vo.getName());
- System.out.println(vo.getKor());
- System.out.println(vo.getEng());
- System.out.println(vo.getMath());
- System.out.println(vo.getTotal());
- System.out.println(vo.getAvg());
- System.out.println(vo.getGrade());
- return "failed..";
- }
- public Test02ScoreVO search(Test02ScoreVO vo2) {
- Test02ScoreVO vo = new Test02ScoreVO();
- System.out.println(vo2.getNum());
- if (vo2.getNum() == 777) {
- vo.setName("KIM");
- vo.setKor(88);
- vo.setEng(89);
- vo.setMath(90);
- }
- return vo;
- }
- //Test02ScoreVO 타입을 여러개 리턴하는 메소드 select(인자없음)를 생성하시오(임의의 값 세팅)
- //메인에서 리턴 받고 출력
- // public Test02ScoreVO[] select() {
- // Test02ScoreVO[] vos = new Test02ScoreVO[3];
- //
- // Test02ScoreVO vo01 = new Test02ScoreVO();
- // vo01.setNum(1);
- // vo01.setName("KIM");
- // vo01.setKor(90);
- // vo01.setEng(95);
- // vo01.setMath(92);
- //
- // Test02ScoreVO vo02 = new Test02ScoreVO();
- // vo02.setNum(2);
- // vo02.setName("LEE");
- // vo02.setKor(88);
- // vo02.setEng(89);
- // vo02.setMath(85);
- //
- // Test02ScoreVO vo03 = new Test02ScoreVO();
- // vo03.setNum(3);
- // vo03.setName("PARK");
- // vo03.setKor(78);
- // vo03.setEng(79);
- // vo03.setMath(70);
- //
- // vos[0] = vo01;
- // vos[1] = vo02;
- // vos[2] = vo03;
- //
- //
- //
- // return vos;
- // }
- public Test02ScoreVO[] select() {
- Test02ScoreVO[] vos = new Test02ScoreVO[3];
- for (int i = 0; i < vos.length; i++) {
- Test02ScoreVO vo = new Test02ScoreVO();
- vos[i] = vo;
- }
- return vos;
- }
- public String delete(Test02ScoreVO vo) {
- vo = null;
- return "deleted..";
- }
- }
- package test.com;
- public class Test02ScoreMain {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("score...");
- Test02ScoreVO vo = new Test02ScoreVO();
- vo.setName("KIM");
- vo.setKor(90);
- vo.setEng(99);
- vo.setMath(88);
- Test02ScoreDAO dao = new Test02ScoreDAO();
- String result = dao.insert(vo);
- System.out.println(result);
- String result2 = dao.update(vo);
- System.out.println(result2);
- String result3 = dao.delete(vo);
- System.out.println(result3);
- vo.setNum(777);
- System.out.println("=========================");
- Test02ScoreVO svo = dao.search(vo);
- System.out.println(svo.getNum());
- System.out.println(svo.getName());
- System.out.println(svo.getKor());
- System.out.println(svo.getEng());
- System.out.println(svo.getMath());
- System.out.println(svo.getTotal());
- System.out.println(svo.getAvg());
- System.out.println(svo.getGrade());
- System.out.println("======================================");
- // Test02ScoreVO[] vos = dao.select();
- // System.out.println("cnt : " + vos.length);
- // for (int i = 0; i < vos.length; i++) {
- // System.out.print(vos[i].getNum() + " ");
- // System.out.print(vos[i].getName() + " ");
- // System.out.print(vos[i].getKor() + " ");
- // System.out.print(vos[i].getEng() + " ");
- // System.out.println(vos[i].getMath() + " ");
- // }
- Test02ScoreVO[] vos = dao.select();
- for (Test02ScoreVO x : vos) {
- System.out.println(x);
- }
- }
- }
- package test.com;
- public class Test02ScoreVO {
- private int num;
- private String name;
- private int kor;
- private int eng;
- private int math;
- private int total;
- private double avg;
- private String grade;
- public int getNum() {
- return num;
- }
- public void setNum(int num) {
- this.num = num;
- }
- 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 getMath() {
- return math;
- }
- public void setMath(int math) {
- this.math = math;
- }
- public int getTotal() {
- total = this.kor + this.eng + this.math;
- return total;
- }
- public double getAvg() {
- avg = (int)((total / 3.0)*10) / 10d ;
- return avg;
- }
- public String getGrade() {
- if (avg >= 90) {
- grade = "A";
- } else if(avg >= 80) {
- grade = "B";
- } else if(avg >= 70) {
- grade = "C";
- } else if(avg >= 60) {
- grade = "D";
- } else {
- grade = "Otehr";
- }
- return grade;
- }
- }
728x90
반응형
'JAVA > 10. Method3' 카테고리의 다른 글
Method 예제 4 (Board) (0) | 2016.06.29 |
---|---|
Method 예제 3 (Member) (0) | 2016.06.29 |
Method 예제 1 (0) | 2016.06.22 |