본문 바로가기

JAVA/국비 공부

3월15일(예제2)

객체를 사용한 성적 관리 프로그램
단. 지금 당장은 한명의 정보만 입력하고 출력해보자.

 

package day0315;

import util.ScannerUtil;
import java.util.Scanner;

public class GradeBook02 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 정보를 저장할 Student 객체를 선언과 초기화
        Student s = new Student();
        // 객체의 필드 혹은 메소드를 접근할때에는
        // 객체. 으로 접근하게 된다.
        // 그래서 . 은 자바에서는 접근 연산자라고 부른다.
        s.id = ScannerUtil.nextInt(scanner, "번호를 입력해주세요");
        s.name = ScannerUtil.nextLine(scanner, "이름을 입력해주세요");
        s.korean = ScannerUtil.nextInt(scanner, "국어점수를 입력해주세요", 0, 100);
        s.english = ScannerUtil.nextInt(scanner, "영어점수를 입력해주세요", 0, 100);
        s.math = ScannerUtil.nextInt(scanner, "수학점수를 입력해주세요", 0, 100);

        // 정보를 출력할 때에는 별다른 것 할 것 없이
        // 그냥 Student 클래스의 객체인 s의 showInfo()를 실행해 주면 된다.
        s.showInfo();
        

        scanner.close();

    }

}

'JAVA > 국비 공부' 카테고리의 다른 글

3월15일 수업(예제4)  (0) 2021.03.15
3월15일 수업(예제3)  (0) 2021.03.15
3월15일 (예제1)  (0) 2021.03.15
3월 15일 수업(예제)  (0) 2021.03.15
3월15일 수업  (0) 2021.03.15