관리 메뉴

nalaolla

For 점수관리 예제 본문

JAVA/3. Control

For 점수관리 예제

날아올라↗↗ 2015. 12. 20. 16:55
728x90
  1. package test.com;
  2.  
  3. public class Test11Score {
  4.  
  5.     public static void main(String[] args) {
  6.         // 성적처리 프로그램
  7.         String nKor = "국어";
  8.         String nEng = "영어";
  9.         String nMath = "수학";
  10.        
  11.         int korScore = 50;
  12.         int engScore = 64;
  13.         int mathScore = 68;
  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.         for (int i = 0; i < 3; i++) {
  31.  
  32.             korScore = (int) (Math.random()*100);
  33.             engScore = (int) (Math.random()*100);
  34.             mathScore = (int) (Math.random()*100);
  35.  
  36.             totalSum = korScore + engScore + mathScore;
  37.             // double totalAvg = (double) totalSum / 3;
  38.             totalAvg = Math.round(((double) totalSum / 3) * 10) / 10d;
  39.  
  40.             System.out.println(i + ". " + nKor + inputComment + korScore + "점");
  41.             System.out.println(i + ". " + nEng + inputComment + engScore + "점");
  42.             System.out.println(i + ". " + nMath + inputComment + mathScore + "점");
  43.  
  44.             System.out.println(line);
  45.  
  46.             System.out.println(" " + i + ". 총점 : " + totalSum + "점");
  47.             System.out.println(" " + i + ". 평균 : " + totalAvg + "점");
  48.  
  49.             String grade = "";
  50.  
  51.             if (totalAvg >= 90) {
  52.                 grade = "A Class";
  53.             } else if (totalAvg >= 80) {
  54.                 grade = "B Class";
  55.             } else if (totalAvg >= 70) {
  56.                 grade = "C Class";
  57.             } else if (totalAvg >= 60) {
  58.                 grade = "D Class";
  59.             } else {
  60.                 grade = "Other Class";
  61.             }
  62.  
  63.             System.out.println(" " + i + ". 등급 : "+ grade);
  64.  
  65.             System.out.println(line);
  66.         }
  67.  
  68.         System.out.println("프로그램을 종료합니다..");
  69.  
  70.     } // end main()
  71.  
  72. }


728x90

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

for 예제  (0) 2015.12.20
switch~case 게임예제  (0) 2015.12.20
switch~case~break 자판기 예제  (0) 2015.12.20
switch~case~break 성적관리 예제  (0) 2015.12.20
Switch~Case~Break 예제2  (0) 2015.12.20