관리 메뉴

nalaolla

switch~case~break 성적관리 예제 본문

JAVA/3. Control

switch~case~break 성적관리 예제

날아올라↗↗ 2015. 12. 20. 16:50
728x90
  1. package test.com;
  2.  
  3. public class Test07Score {
  4.  
  5.     public static void main(String[] args) {
  6.         //성적처리 프로그램
  7.         String nKor = "국어";
  8.         String nEng = "영어";
  9.         String nMath = "수학";
  10.  
  11.         int korScore = 80;
  12.         int engScore = 54;
  13.         int mathScore = 98;
  14.  
  15.         int totalSum = korScore + engScore + mathScore;
  16.         //double totalAvg = (double) totalSum / 3;
  17.         double totalAvg =  Math.round(((double) totalSum / 3)*10)/10d ;
  18.  
  19.         String inputComment = " 점수를 입력학세요 : ";
  20.         String line = "========================";
  21.  
  22.         // 변수의 상수 처리를 위한 final
  23.         final String TITLE = "[성적처리 프로그램]";
  24.  
  25.         // TITLE = "aaaaa";
  26.  
  27.         System.out.println(TITLE);
  28.         System.out.println(line);
  29.  
  30.         System.out.println(nKor + inputComment + korScore + "점");
  31.         System.out.println(nEng + inputComment + engScore + "점");
  32.         System.out.println(nMath + inputComment + mathScore + "점");
  33.  
  34.         System.out.println(line);
  35.  
  36.         System.out.println(" 총점 : " + totalSum + "점");
  37.         System.out.println(" 평균 : " + totalAvg + "점");
  38.  
  39.         /*
  40.         String grade = "";
  41.  
  42.         if (totalAvg >= 90) {
  43.             grade = "A Class";
  44.         } else if (totalAvg >= 80) {
  45.             grade = "B Class";
  46.         } else if (totalAvg >= 70) {
  47.             grade = "C Class";
  48.         } else if (totalAvg >= 60) {
  49.             grade = "D Class";
  50.         } else {
  51.             grade = "Other Class";
  52.         }
  53.          */
  54.        
  55.         /*int gradeCode = 0;
  56.         if (totalAvg >= 60) gradeCode = 4;
  57.         if (totalAvg >= 70) gradeCode = 3;
  58.         if (totalAvg >= 80) gradeCode = 2;
  59.         if (totalAvg >= 90) gradeCode = 1;
  60.         */
  61.         String grade = "";
  62.        
  63.         int AvgScore = (int)(totalAvg/10d)*10;
  64.        
  65.         switch(AvgScore) {
  66.             case 100 : case 90 :
  67.                 grade = "A Class";
  68.                 break;
  69.             case 80 :
  70.                 grade = "B Class";
  71.                 break;
  72.             case 70 :
  73.                 grade = "C Class";
  74.                 break;
  75.             case 60 :
  76.                 grade = "D Class";
  77.                 break;
  78.             default :
  79.                 grade = "Other Class";
  80.         }
  81.        
  82.        
  83.         System.out.println(" 등급 : " + grade);
  84.  
  85.         System.out.println(line);
  86.         System.out.println("프로그램을 종료합니다..");
  87.        
  88.        
  89.        
  90.     } // end main()
  91.    
  92. }


728x90

'JAVA > 3. Control' 카테고리의 다른 글

switch~case 게임예제  (0) 2015.12.20
switch~case~break 자판기 예제  (0) 2015.12.20
Switch~Case~Break 예제2  (0) 2015.12.20
Switch~Case~Break  (0) 2015.12.20
자바는 블럭단위 처리다.  (0) 2015.12.20