관리 메뉴

nalaolla

성적처리 프로그램 예제1 본문

JAVA/1. 기본문법01

성적처리 프로그램 예제1

날아올라↗↗ 2015. 12. 1. 01:27
728x90
  1. package test.com;
  2.  
  3. public class Test04Score {
  4.  
  5.     public static void main(String[] args) {
  6.         //성적처리 프로그램
  7.         String nKor = "국어";
  8.         String nEng = "영어";
  9.         String nMath = "수학";
  10.        
  11.         int korScore = 100;
  12.         int engScore = 49;
  13.         int mathScore = 98;
  14.        
  15.         int totalSum = korScore+engScore+mathScore;
  16.         double totalAvg = totalSum/3;
  17.        
  18.         String inputComment = " 점수를 입력학세요 : ";
  19.         String line = "========================";
  20.        
  21.         //변수의 상수 처리를 위한 final
  22.         final String TITLE = "[성적처리 프로그램]";
  23.        

  24.        
  25.         System.out.println(TITLE);
  26.         System.out.println(line);
  27.        
  28.         System.out.println(nKor + inputComment + korScore);
  29.         System.out.println(nEng + inputComment + engScore);
  30.         System.out.println(nMath + inputComment + mathScore);
  31.        
  32.         System.out.println(line);
  33.        
  34.         System.out.println(" 총점 : " + totalSum);
  35.         System.out.println(" 평균 : " + totalAvg);
  36.         String grade = "";
  37.         grade =
  38.                 totalAvg >=90 ? "A Class" :
  39.                     totalAvg >=80 ? "B Class" :
  40.                         totalAvg >=70 ? "C Class" :
  41.                             "D Class";
  42.         System.out.println(" 등급 : " + grade);
  43.        
  44.         System.out.println(line);
  45.         System.out.println("프로그램을 종료합니다..");
  46.        
  47.         System.out.println("공자왈 "지덕체" ");
  48.         System.out.println("1000\10");
  49.        
  50.         //  http://www.naver.com
  51.         // c:javastudy emp    --> c:\javastudy\temp
  52.     }
  53.  
  54. }

============================================

성적처리 프로그램 예제01


[라인설명]

7~9 : 각 과목명 String변수 초기화

11~13 : 각 과목점수 int변수 초기화

15 : 총점 int 초기화

16 : 평균 double타입 초기화

22 : 프로그램 제목은 변경할 일이 없으므로 final설정하여 재정의 불가설정

37 : 등급정의

38~42 : 3항연산자를 사용하여 각 점수대별 등급을 정리

728x90

'JAVA > 1. 기본문법01' 카테고리의 다른 글

게시판예제 01  (0) 2015.12.01
성적처리 프로그램 예제2 (Scanner사용)  (0) 2015.12.01
타입별 System.out.println(...)  (0) 2015.12.01
이클립스 기본 단축키 정리  (0) 2015.12.01
Hello, Java  (0) 2015.12.01