관리 메뉴

nalaolla

성적처리 프로그램 예제2 (Scanner사용) 본문

JAVA/1. 기본문법01

성적처리 프로그램 예제2 (Scanner사용)

날아올라↗↗ 2015. 12. 1. 01:31
728x90
  1. package test.com;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Test04Score2 {
  6.  
  7.     public static void main(String[] args) {
  8.        
  9.         Test04ScoreSub scoresub = new Test04ScoreSub();
  10.         scoresub.ScorePrint();
  11.        
  12.     }
  13.  
  14. }
  15.  
  16. class Test04ScoreSub{
  17.     public void ScorePrint(){
  18.         System.out.println("[성적관리 프로그램]");
  19.         System.out.println("=========================");
  20.        
  21.         Scanner scanner = new Scanner(System.in);
  22.         System.out.println("국어점수입력");
  23.         int korScore = scanner.nextInt();
  24.         System.out.println("영어점수입력");
  25.         int engScore = scanner.nextInt();
  26.         System.out.println("수학점수입력");
  27.         int mathScore = scanner.nextInt();
  28.        
  29.         int scoreSum = 0;
  30.         double scoreAvg = 0;
  31.        
  32.         scoreSum = korScore + engScore + mathScore;
  33.         scoreAvg = scoreSum / 3;
  34.        
  35.         System.out.println("=========================");
  36.         System.out.println("총점 : " + scoreSum);
  37.         System.out.println("평균 : " + scoreAvg);
  38.         System.out.println("=========================");
  39.         System.out.println("[프로그램 종료]");
  40.        
  41.         scanner.close();
  42.     }
  43. }

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

성적처리01 예제와 비슷


Test04Score2 클래스와 실제 기능구현하는 Test04ScoreSub로 구분하여 진행

Test04Score2에서 Test04ScoreSub의 인스턴스 생성후 해당 메소드인 ScorePrint()호출


java.uti.Scanner클래스 인스턴스 객체 생성후 Console창에서 해당 내용을 입력받아 정보 출력하는 방식

728x90

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

기본자료형 및 변수선언 정리1  (0) 2015.12.01
게시판예제 01  (0) 2015.12.01
성적처리 프로그램 예제1  (0) 2015.12.01
타입별 System.out.println(...)  (0) 2015.12.01
이클립스 기본 단축키 정리  (0) 2015.12.01