관리 메뉴

nalaolla

Method 예제 2 (Score) 본문

JAVA/10. Method3

Method 예제 2 (Score)

날아올라↗↗ 2016. 6. 29. 15:07
728x90
  1. package test.com;
  2.  
  3. public class Test02ScoreDAO {
  4.    
  5.     public String insert(Test02ScoreVO vo) {
  6.         System.out.println(vo);
  7.         System.out.println("데이터 저장 처리 완료");
  8.        
  9.         System.out.println(vo.getName());
  10.         System.out.println(vo.getKor());
  11.         System.out.println(vo.getEng());
  12.         System.out.println(vo.getMath());
  13.         System.out.println(vo.getTotal());
  14.         System.out.println(vo.getAvg());
  15.         System.out.println(vo.getGrade());
  16.        
  17.        
  18.         return "success..";
  19.     }
  20.    
  21.     public String update(Test02ScoreVO vo) {
  22.         System.out.println(vo);
  23.         System.out.println("데이터 수정 처리 완료");
  24.        
  25.         System.out.println(vo.getName());
  26.         System.out.println(vo.getKor());
  27.         System.out.println(vo.getEng());
  28.         System.out.println(vo.getMath());
  29.         System.out.println(vo.getTotal());
  30.         System.out.println(vo.getAvg());
  31.         System.out.println(vo.getGrade());
  32.        
  33.        
  34.         return "failed..";
  35.     }
  36.    
  37.    
  38.     public Test02ScoreVO search(Test02ScoreVO vo2) {
  39.         Test02ScoreVO vo = new Test02ScoreVO();
  40.         System.out.println(vo2.getNum());
  41.         if (vo2.getNum() == 777) {
  42.             vo.setName("KIM");
  43.             vo.setKor(88);
  44.             vo.setEng(89);
  45.             vo.setMath(90);
  46.            
  47.         }
  48.         return vo;
  49.     }
  50.    
  51.    
  52.     //Test02ScoreVO 타입을 여러개 리턴하는 메소드 select(인자없음)를 생성하시오(임의의 값 세팅)
  53.     //메인에서 리턴 받고 출력
  54.    
  55. //  public Test02ScoreVO[] select() {
  56. //    Test02ScoreVO[] vos = new Test02ScoreVO[3];
  57. //   
  58. //    Test02ScoreVO vo01 = new Test02ScoreVO();
  59. //    vo01.setNum(1);
  60. //    vo01.setName("KIM");
  61. //    vo01.setKor(90);
  62. //    vo01.setEng(95);
  63. //    vo01.setMath(92);
  64. //   
  65. //    Test02ScoreVO vo02 = new Test02ScoreVO();
  66. //    vo02.setNum(2);
  67. //    vo02.setName("LEE");
  68. //    vo02.setKor(88);
  69. //    vo02.setEng(89);
  70. //    vo02.setMath(85);
  71. //   
  72. //    Test02ScoreVO vo03 = new Test02ScoreVO();
  73. //    vo03.setNum(3);
  74. //    vo03.setName("PARK");
  75. //    vo03.setKor(78);
  76. //    vo03.setEng(79);
  77. //    vo03.setMath(70);
  78. //   
  79. //    vos[0] = vo01;
  80. //    vos[1] = vo02;
  81. //    vos[2] = vo03;
  82. //   
  83. //   
  84. //   
  85. //    return vos;
  86. //  }
  87.    
  88.     public Test02ScoreVO[] select() {
  89.         Test02ScoreVO[] vos = new Test02ScoreVO[3];
  90.        
  91.        
  92.         for (int i = 0; i < vos.length; i++) {
  93.             Test02ScoreVO vo = new Test02ScoreVO();
  94.             vos[i] = vo;
  95.         }
  96.        
  97.         return vos;
  98.     }
  99.    
  100.    
  101.     public String delete(Test02ScoreVO vo) {
  102.         vo = null;
  103.        
  104.        
  105.         return "deleted..";
  106.     }
  107.    
  108.  
  109. }





  1. package test.com;
  2.  
  3. public class Test02ScoreMain {
  4.  
  5.     public static void main(String[] args) {
  6.         // TODO Auto-generated method stub
  7.         System.out.println("score...");
  8.        
  9.         Test02ScoreVO vo = new Test02ScoreVO();
  10.         vo.setName("KIM");
  11.         vo.setKor(90);
  12.         vo.setEng(99);
  13.         vo.setMath(88);
  14.        
  15.         Test02ScoreDAO dao = new Test02ScoreDAO();
  16.        
  17.         String result = dao.insert(vo);
  18.         System.out.println(result);
  19.        
  20.         String result2 = dao.update(vo);
  21.         System.out.println(result2);
  22.        
  23.         String result3 = dao.delete(vo);
  24.         System.out.println(result3);
  25.        
  26.        
  27.         vo.setNum(777);
  28.         System.out.println("=========================");
  29.        
  30.         Test02ScoreVO svo =  dao.search(vo);
  31.         System.out.println(svo.getNum());
  32.         System.out.println(svo.getName());
  33.         System.out.println(svo.getKor());
  34.         System.out.println(svo.getEng());
  35.         System.out.println(svo.getMath());
  36.         System.out.println(svo.getTotal());
  37.         System.out.println(svo.getAvg());
  38.         System.out.println(svo.getGrade());
  39.        
  40.         System.out.println("======================================");
  41.        
  42. //    Test02ScoreVO[] vos = dao.select();
  43. //    System.out.println("cnt : " + vos.length);
  44. //    for (int i = 0; i < vos.length; i++) {
  45. //      System.out.print(vos[i].getNum() + " ");
  46. //      System.out.print(vos[i].getName() + " ");
  47. //      System.out.print(vos[i].getKor() + " ");
  48. //      System.out.print(vos[i].getEng() + " ");
  49. //      System.out.println(vos[i].getMath() + " ");
  50. //    }
  51.        
  52.        
  53.         Test02ScoreVO[] vos = dao.select();
  54.         for (Test02ScoreVO x : vos) {
  55.             System.out.println(x);
  56.         }
  57.  
  58.     }
  59.  
  60. }




  1. package test.com;
  2.  
  3. public class Test02ScoreVO {
  4.     private int num;
  5.     private String name;
  6.     private int kor;
  7.     private int eng;
  8.     private int math;
  9.     private int total;
  10.     private double avg;
  11.     private String grade;
  12.    
  13.     public int getNum() {
  14.         return num;
  15.     }
  16.  
  17.     public void setNum(int num) {
  18.         this.num = num;
  19.     }
  20.  
  21.     public String getName() {
  22.         return name;
  23.     }
  24.  
  25.     public void setName(String name) {
  26.         this.name = name;
  27.     }
  28.  
  29.     public int getKor() {
  30.         return kor;
  31.     }
  32.  
  33.     public void setKor(int kor) {
  34.         this.kor = kor;
  35.     }
  36.  
  37.     public int getEng() {
  38.         return eng;
  39.     }
  40.  
  41.     public void setEng(int eng) {
  42.         this.eng = eng;
  43.     }
  44.  
  45.     public int getMath() {
  46.         return math;
  47.     }
  48.  
  49.     public void setMath(int math) {
  50.         this.math = math;
  51.     }
  52.  
  53.     public int getTotal() {
  54.         total = this.kor + this.eng + this.math;
  55.         return total;
  56.     }
  57.  
  58.    
  59.     public double getAvg() {
  60.         avg = (int)((total / 3.0)*10) / 10d ;
  61.         return avg;
  62.     }
  63.  
  64.    
  65.  
  66.     public String getGrade() {
  67.        
  68.         if (avg >= 90) {
  69.             grade = "A";
  70.         } else if(avg >= 80) {
  71.             grade = "B";
  72.         } else if(avg >= 70) {
  73.             grade = "C";
  74.         } else if(avg >= 60) {
  75.             grade = "D";
  76.         } else {
  77.             grade = "Otehr";
  78.         }
  79.         return grade;
  80.     }
  81.  
  82.    
  83. }


728x90

'JAVA > 10. Method3' 카테고리의 다른 글

Method 예제 4 (Board)  (0) 2016.06.29
Method 예제 3 (Member)  (0) 2016.06.29
Method 예제 1  (0) 2016.06.22