Java 웹 개발

21.08.30 - 웹 개발 입문 14일차

개발이란 2021. 8. 30. 22:49

객체 지향 프로그래밍

OOP(Object Oriented Programming), 객체 지향 프로그래밍은 단어 뜻 그대로 객체를 적극적으로 활용하여 프로그래밍하는 방식을 말한다. 독립된 객체(Object)들을 만들어 서로 상호작용하며 현실 세계와 유사한 형태로 프로그래밍 하는 것을 목표로 하는 설계 방법을 의미한다.

 

 

<클래스>
클래스는 객체를 만들기 위한 준비도구(설계도)

멤버변수들을 하나의 타입으로 묶어 주는 것이 클래스이다

 

<객체(object)와 인스턴스(instance)>

객체와 크게 구분하지 않고 사용한다

 

<멤버변수>
메세지에 들어있어야 하는 정보들을 변수로 선언
정보에 설정될 데이터는 "만들어지는 시점"에 알 수 있으므로 특별한 경우가 아니라면 설정하지 않는다
String name;
String content;
String time;

 

ex. 객체 생성

Message first = new Message();

Message = 참조형

first = 리모컨

Message() = 본체(대상)

 

 

 

Q. 다음 데이터들을 객체화 하여 구현하고 출력하세요

-> 데이터를 체계적으로 정리하여 객체화

국가명 금메달 은메달 동메달 순위
미국 39 41 33 1
중국 38 32 18 2
일본 27 14 17 3
영국 22 21 22 4

 

-> 구성요소 : 국가명, 금메달 개수, 은메달 개수, 동메달 개수, 순위

package oop.basic2;

public class Country {
	// <멤버변수> = 나라명(String) + 금메달(int) + 은메달(int) + 동메달(int) + 순위(int)

	String name;
	int gold;
	int silver;
	int bronze;
	int rank;

}
package oop.basic2;

import oop.basic2.Country;

public class Test01 {
	public static void main(String[] args) {
		//올림픽 4개국 메달 정보를 구현
		//= Country 객체 4개 생성 후 초기화 및 출력

		Country a = new Country();

		a.name = "미국";
		a.gold = 39;
		a.silver = 41;
		a.bronze = 33;
		a.rank = 1;

		System.out.println("이름 : "+a.name);
		System.out.println("금메달 : "+a.gold);
		System.out.println("은메달 : "+a.silver);
		System.out.println("동메달 : "+a.bronze);
		System.out.println("순위 : "+a.rank);

		Country b = new Country();

		b.name = "중국";
		b.gold = 38;
		b.silver = 32;
		b.bronze = 18;
		b.rank = 2;

		System.out.println("이름 : "+b.name);
		System.out.println("금메달 : "+b.gold);
		System.out.println("은메달 : "+b.silver);
		System.out.println("동메달 : "+b.bronze);
		System.out.println("순위 : "+b.rank);

		Country c = new Country();

		c.name = "일본";
		c.gold = 27;
		c.silver = 14;
		c.bronze = 17;
		c.rank = 3;

		System.out.println("이름 : "+c.name);
		System.out.println("금메달 : "+c.gold);
		System.out.println("은메달 : "+c.silver);
		System.out.println("동메달 : "+c.bronze);
		System.out.println("순위 : "+c.rank);

		Country d = new Country();

		d.name = "영국";
		d.gold = 22;
		d.silver = 21;
		d.bronze = 22;
		d.rank = 4;

		System.out.println("이름 : "+d.name);
		System.out.println("금메달 : "+d.gold);
		System.out.println("은메달 : "+d.silver);
		System.out.println("동메달 : "+d.bronze);
		System.out.println("순위 : "+d.rank);
	}
}

- 정답

이름 : 미국
금메달 : 39
은메달 : 41
동메달 : 33
순위 : 1
이름 : 중국
금메달 : 38
은메달 : 32
동메달 : 18
순위 : 2
이름 : 일본
금메달 : 27
은메달 : 14
동메달 : 17
순위 : 3
이름 : 영국
금메달 : 22
은메달 : 21
동메달 : 22
순위 : 4

 

 

 

Q. 다음 데이터들을 객체화 하여 구현하고 출력하세요

이름 종목 금메달 은메달 동메달
김연아 피겨스케이팅 2 0 1
이상화 스피드스케이팅 1 2 1
윤성빈 스켈레톤 1 0 1

- 일반적으로 풀이

package oop.basic3;

public class Player {
	String name, type;
	int gold, silver, bronze;
}
package oop.basic3;

public class Test01 {
	public static void main(String[] args) {

		//객체 생성
		Player a = new Player();
		Player b = new Player();
		Player c = new Player();

		//초기화
		a.name = "김연아";
		a.type = "피겨스케이팅";
		a.gold = 2;
		a.silver = 0;
		a.bronze = 1;

		b.name = "이상화";
		b.type = "스피드스케이팅";
		b.gold = 1;
		b.silver = 2;
		b.bronze = 1;

		c.name = "윤성빈";
		c.type = "스켈레톤";
		c.gold = 1;
		c.silver = 0;
		c.bronze = 1;

		//출력
		System.out.println("<선수 정보>");
		System.out.println("이름 : "+a.name);
		System.out.println("종목 : "+a.type);
		System.out.println("금메달 "+a.gold+"개");
		System.out.println("은메달 "+a.silver+"개");
		System.out.println("동메달 "+a.bronze+"개");

		System.out.println("<선수 정보>");
		System.out.println("이름 : "+b.name);
		System.out.println("종목 : "+b.type);
		System.out.println("금메달 "+b.gold+"개");
		System.out.println("은메달 "+b.silver+"개");
		System.out.println("동메달 "+b.bronze+"개");

		System.out.println("<선수 정보>");
		System.out.println("이름 : "+c.name);
		System.out.println("종목 : "+c.type);
		System.out.println("금메달 "+c.gold+"개");
		System.out.println("은메달 "+c.silver+"개");
		System.out.println("동메달 "+c.bronze+"개");
	}
}

 

 

- 멤버 메소드 활용 (1)

package oop.basic3;

public class Player {
	//멤버 변수 - 데이터 저장 공간
	String name, type;
	int gold, silver, bronze;

	//멤버 메소드 - 코드 저장 공간
	//void 이름(){ 코드 }
	void showInfo() {
		//a, b, c같은 특정 대상이 아니라 "주인공"을 의미하는 키워드를 사용 = this
		System.out.println("<선수 정보>");
		System.out.println("이름 : "+this.name);
		System.out.println("종목 : "+this.type);
		System.out.println("금메달 "+this.gold+"개");
		System.out.println("은메달 "+this.silver+"개");
		System.out.println("동메달 "+this.bronze+"개");
	}
}
package oop.basic3;

public class Test02 {
	public static void main(String[] args) {

		//객체 생성
		Player a = new Player();
		Player b = new Player();
		Player c = new Player();

		//초기화
		a.name = "김연아";
		a.type = "피겨스케이팅";
		a.gold = 2;
		a.silver = 0;
		a.bronze = 1;

		b.name = "이상화";
		b.type = "스피드스케이팅";
		b.gold = 1;
		b.silver = 2;
		b.bronze = 1;

		c.name = "윤성빈";
		c.type = "스켈레톤";
		c.gold = 1;
		c.silver = 0;
		c.bronze = 1;

		//출력
		a.showInfo();//a를 주인공으로 해서 showInfo 코드 실행!
		b.showInfo();//b를 주인공으로 해서 showInfo 코드 실행!
		c.showInfo();//c를 주인공으로 해서 showInfo 코드 실행!
	}
}

 

- 멤버 메소드 활용 (2)

package oop.basic3;

public class Player {
	// 멤버 변수 - 데이터 저장 공간

	String name;
	String type;
	int gold;
	int silver;
	int bronze;

	// 멤버 메소드 - 코드 저장 공간
	// void 이름(){ 코드 }
	void init(String name, String type, int gold, int silver, int bronze) {
		this.name = name;
		this.type = type;
		this.gold = gold;
		this.silver = silver;
		this.bronze = bronze;
	}

	void showInfo() {
		// a, b, c같은 특정 대상이 아니라 "주인공"을 의미하는 키워드를 사용
		// = this
		System.out.println("<선수 정보>");
		System.out.println("이름 : " + this.name);
		System.out.println("종목 : " + this.type);
		System.out.println("금메달 : " + this.gold);
		System.out.println("은메달 : " + this.silver);
		System.out.println("동메달 : " + this.bronze);
	}

}
package oop.basic3;

public class Test01 {

	public static void main(String[] args) {

		// 객체 생성
		Player a = new Player();
		Player b = new Player();
		Player c = new Player();

		// 초기화
		a.init("김연아", "피겨스케이팅", 2, 0, 1);
		b.init("이상화", "스피드스케이팅", 1, 2, 1);
		c.init("윤성빈", "스켈레톤", 1, 0, 1);

		// 출력
		a.showInfo();// a를 주인공으로 해서 showInfo 코드 실행!
		b.showInfo();// b를 주인공으로 해서 showInfo 코드 실행!
		c.showInfo();// c를 주인공으로 해서 showInfo 코드 실행!

	}
}

- 정답

<선수 정보>
이름 : 김연아
종목 : 피겨스케이팅
금메달 : 2
은메달 : 0
동메달 : 1
<선수 정보>
이름 : 이상화
종목 : 스피드스케이팅
금메달 : 1
은메달 : 2
동메달 : 1
<선수 정보>
이름 : 윤성빈
종목 : 스켈레톤
금메달 : 1
은메달 : 0
동메달 : 1

 

 

 

Q. 다음 데이터를 객체화하여 구현하고 결과를 출력하세요

상품코드 이름 분류 판매가격
A000001 참이슬 주류 1200
A000002 처음처럼 주류 1300
B000001 고무장갑 생필품 2000

 

 

package oop.method1;

public class Mart {
	
	
	String code;
	String name;
	String list;
	int price;
	
	void init(String code, String name, String list, int price) {
		this.code = code;
		this.name = name;
		this.list = list;
		this.price = price;
	}
		
	void showInfo() {
		System.out.println("<마트 상품 정보>");
		System.out.println("상품코드 : "+this.code);
		System.out.println("이름 : "+this.name);
		System.out.println("분류 : "+this.list);
		System.out.println("가격 : "+this.price+"원");
	}
		
	
}
package oop.method1;

public class Test01 {

	public static void main(String[] args) {

		Mart a = new Mart();
		Mart b = new Mart();
		Mart c = new Mart();

		a.init("A00001", "참이슬", "주류", 1200);
		b.init("A00002", "처음처럼", "주류", 1300);
		c.init("B00001", "고무장갑", "생필품", 2000);

		a.showInfo();
		b.showInfo();
		c.showInfo();

	}

}

- 정답

<마트 상품 정보>
상품코드 : A00001
이름 : 참이슬
분류 : 주류
가격 : 1200원
<마트 상품 정보>
상품코드 : A00002
이름 : 처음처럼
분류 : 주류
가격 : 1300원
<마트 상품 정보>
상품코드 : B00001
이름 : 고무장갑
분류 : 생필품
가격 : 2000원

 

 

 

Q. 다음 데이터를 객체화하여 구현하고 결과를 출력하세요

행사중인 상품은 가격이 20% 세일되어 나와야 합니다

이름 종류 가격 행사여부
아메리카노 음료 2000 행사중
프라푸치노 음료 3500 행사아님
치즈케이크 5000 행사중
유기농샌드위치 3000 행사아님

 

 

package oop.method2;

public class Menu {

	String name;
	String list;
	int price;
	boolean isEvent;

	// 멤버 메소드
	// init 메소드는 2가지 버전으로 만들면 어떨까?
	// 1. 이름, 분류, 가격만 전달받으면 행사중이 아닌 상품으로 결정
	// 2. 이름,분류, 가격, 행사여부까지 전달받으면 정보를 그대로 설정
	// --->메소드 오버로딩 (Method Overloading )

	void init(String name, String list, int price) {
		this.name = name;
		this.list = list;
		this.price = price;
		// this.isEvent = price;
	}

	void init(String name, String list, int price, boolean isEvent) {
		this.name = name;
		this.list = list;
		this.price = price;
		this.isEvent = isEvent;
		// this.ise
	}

	void showInfo() {
		System.out.println("<커피숍 메뉴 정보>");
		System.out.println("이름 : " + this.name);
		System.out.println("종류 : " + this.list);
		// System.out.println("가격 : "+this.price+"원");
		// System.out.println("행사여부 : "+ this.isEvent);

		if (this.isEvent) {// 행사 중일때 --> 20% 할인(즉석에서 계산하여 출력)
			int discount = this.price * (100 - 20) / 100;
			System.out.println("가격 : " + discount + "원" + "(원가 : " + this.price + "원) ");

		} else {// 행사중이 아닐 때
			System.out.println("가격 : " + this.price + "원");
		}
	}
}
package oop.method2;

public class Test01 {

	public static void main(String[] args) {
		// 생성
		Menu a = new Menu();
		Menu b = new Menu();
		Menu c = new Menu();
		Menu d = new Menu();

		// 초기화 - init 메소드 호출 = 값을 설정하는 코드
		a.init("아메리카노", "음료", 2000, true);
		b.init("프라포치노", "음료", 3500);
		c.init("치즈케이크", "빵", 5000, true);
		d.init("유기농샌드위치", "빵", 3000);

		// 출력 - showInfo 메소드 호출 = 출력 값을 화면에 표시하는 코드
		a.showInfo();
		b.showInfo();
		c.showInfo();
		d.showInfo();

	}

}

- 정답

<커피숍 메뉴 정보>
이름 : 아메리카노
종류 : 음료
가격 : 1600원(원가 : 2000원) 
<커피숍 메뉴 정보>
이름 : 프라포치노
종류 : 음료
가격 : 3500원
<커피숍 메뉴 정보>
이름 : 치즈케이크
종류 : 빵
가격 : 4000원(원가 : 5000원) 
<커피숍 메뉴 정보>
이름 : 유기농샌드위치
종류 : 빵
가격 : 3000원

 

 

 

- 세터 메소드(setter method)

정보는 언제든지 바뀔 수 있다
전체가 아닌 하나씩 변경할 수 있도록 메소드를 준비
세터 메소드(setter method) = 설정 전용 메소드
변수명을 이용해서 메소드 이름을 구성
set + 변수명 으로 메소드 이름을 작성
set + name 이면 setName 이라고 이름지어진다
조건을 추가하여 "원하는 값"만 설정

package oop.method3;

public class Toy {
	String name;
	int price;

	void init(String name, int price) {
		// setName 메소드 실행해!
		this.setName(name);
		this.setPrice(price);
	}

	void showInfo() {
		System.out.println("이름 : " + this.name);
		System.out.println("가격 : " + this.price + "원");
	}

	void setName(String name) {
		this.name = name;
	}

	void setPrice(int price) {
//	if(올바른 가격이라면) {
		if (price >= 0) {
			this.price = price;
		}
	}

}
package oop.method3;

public class Test01 {

	public static void main(String[] args) {
		Toy t = new Toy();

		t.init("아기상어", 15000);
		t.showInfo();
		
		//문제점
		//정보를 변경하려면 무조건 두 개를 작성해야 한다
		//이게 싫으면 변수를 직접 컨트롤해야 비추천!
		
		//t.init("아기상어", 20000);// 가격만 수정?
		t.setPrice(20000);
		
		//t.init("Baby shark",20000);// 이름만 수정?
		t.setName("Baby Shark");
		
		t.showInfo();

	}

}

- 정답

변경전

이름 : 아기상어
가격 : 15000원

 

변경후
이름 : Baby Shark
가격 : 20000원

 

 

Q. 다음 데이터를 객체화하여 구현하고 결과를 출력하세요

이름 과목 서술형점수 평가자체크리스트점수
피카츄 응용SW기초기술활용 50 60
라이츄 응용SW기초기술활용 40 80
파이리 프로그래밍언어활용 60 65

 

 

 

세터 메소드 사용

package oop.method4;

public class Student {
	// 멤버 변수 - 데이터

	String name;
	String subject;
	int score; // 서술형 시험 점수
	int checkScore; // 체크리스트 시험 점수

	// 멤버 메소드 - 코드(기능)
	// - 세터 메소드 4개 - setName, setSubject, setScore, setCheckScore
	// - init 메소드
	// - showInfo 메소드

	void setName(String name) {
		this.name = name;
	}

	void setSubject(String subject) {
		this.subject = subject;
	}

	void setScore(int score) {
		if (score >= 0 && score <= 100) { // 올바른 점수(0~100)라면
			this.score = score;
		}
	}

	void setCheckScore(int checkScore) {
		if (checkScore <= 0 && checkScore >= 100) { // 잘못된 점수(0미만 100초과)라면
			return;// 메소드 실행을 중지하는 키워드
		}
		this.checkScore = checkScore;
	}

	void init(String name, String subject, int score, int checkScore) {
		this.setName(name);
		this.setSubject(subject);
		this.setScore(score);
		this.setCheckScore(checkScore);
	}

	void showInfo() {
		System.out.println("<우리반 성적 정보>");

		// 일반 정보들은 멤버 변수로 관리해야 한다.
		// =학생의 고유정보이기 때문
		System.out.println("이름 : " + this.name);
		System.out.println("과목 : " + this.subject);
		System.out.println("서술형점수 : " + this.score + "점");
		System.out.println("평가자체크리스트점수 : " + this.checkScore + "점");

		// 합계, 평균, 합격/불합격 정보등은 그때그때 계산해야하는 정보이다.
		// = 변경되는 점수가 반영되어야 하기 때문!
		int total = this.score + this.checkScore;
		float average = total / 2.0f;
		System.out.println("평균점수 : " + average + "점");

		boolean isPass = average >= 60 && this.score >= 40 && this.checkScore >= 40;
		if (isPass) {
			System.out.println("해당 시험에 통과하였습니다");
		} else {
			System.out.println("해당 시험 재평가 응시 대상자입니다");
		}
	}

}
package oop.method4;

public class Test01 {
	public static void main(String[] args) {

		// 생성
		Student a = new Student();
		Student b = new Student();
		Student c = new Student();

		// 초기화
		a.init("피카츄", "응용SW기초기술활용", 50, 60);
		b.init("라이츄", "응용SW기초기술활용", 40, 80);
		c.init("파이리", "프로그래밍언어활용", 60, 65);

		// 변경
		// a.setScore(55);//a의 서술형평가를 55점으로 변경!

		// 출력
		a.showInfo();
		b.showInfo();
		c.showInfo();
	}
}

 

Getter 메소드(게터 메소드)

원하는 정보를 원하는 형태로 반환하는 메소드
Getter 메소드(게터 메소드)
Setter 메소드처럼 이름을 짓고, Setter 메소드 처럼 변수당 1개씩은 기본적으로 생성
필요하다면 추가적으로 더 생성할 수도 있다
ex : name의 getter 메소드는 getName이다
return 은 메소드를 중지하는 키워드이며, 우측에 값이 있으면 해당 값을 "호출자"에게 반환
void는 실행 후 반환할 데이터가 없다는 뜻이다(null과 구분할 줄 알아야함)

 

 

- 게터 메소드 사용

package oop.method5;

public class Student {
	// 멤버 변수 - 데이터

	String name;
	String subject;
	int score; // 서술형 시험 점수
	int checkScore; // 체크리스트 시험 점수

	// 멤버 메소드 - 코드(기능)
	// - 세터 메소드 4개 - setName, setSubject, setScore, setCheckScore
	// - init 메소드
	// - showInfo 메소드

	void setName(String name) {
		this.name = name;
	}

	void setSubject(String subject) {
		this.subject = subject;
	}

	void setScore(int score) {
		if (score >= 0 && score <= 100) { // 올바른 점수(0~100)라면
			this.score = score;
		}
	}

	void setCheckScore(int checkScore) {
		if (checkScore <= 0 && checkScore >= 100) { // 잘못된 점수(0미만 100초과)라면
			return;// 메소드 실행을 중지하는 키워드
		}
		this.checkScore = checkScore;
	}

	void init(String name, String subject, int score, int checkScore) {
		this.setName(name);
		this.setSubject(subject);
		this.setScore(score);
		this.setCheckScore(checkScore);
	}


	
	String getName() {
		return this.name; // 주인공(this)의 이름을 부른 대상에게 반환하세요
	}

	String getSubject() {
		return this.subject;
	}

	int getScore() {
		return this.score;
	}

	int getCheckScore() {
		return this.checkScore;
	}

	int getTotal() {
		return this.score + this.checkScore;
	}

	float getAverage() {
		// return (this.score+this.checkScore)/2.0f;
		return this.getTotal() / 2.0f;
	}

	boolean getPass() {
		return this.score >= 40 && this.checkScore >= 40 && this.getAverage() >= 60;
	}

	void showInfo() {
		System.out.println("<우리반 성적 정보>");

		// 일반 정보들은 멤버 변수로 관리해야 한다.
		// =학생의 고유정보이기 때문
		System.out.println("이름 : " + this.name);
		System.out.println("과목 : " + this.subject);
		System.out.println("서술형점수 : " + this.score + "점");
		System.out.println("평가자체크리스트점수 : " + this.checkScore + "점");

		System.out.println("평균점수 : " + this.getAverage() + "점");

		if (this.getPass()) {
			System.out.println("해당 시험에 통과하였습니다");
		} else {
			System.out.println("해당 시험 재평가 응시 대상자입니다");
		}
	}

}
package oop.method5;

public class Test01 {
	public static void main(String[] args) {

		// 생성
		Student a = new Student();
		Student b = new Student();
		Student c = new Student();

		// 초기화
		a.init("피카츄", "응용SW기초기술활용", 50, 60);
		b.init("라이츄", "응용SW기초기술활용", 40, 80);
		c.init("파이리", "프로그래밍언어활용", 60, 65);

		// 변경
		// a.setScore(55);//a의 서술형평가를 55점으로 변경!

		// 출력
		a.showInfo();
		b.showInfo();
		c.showInfo();
	}
}

- 정답

<우리반 성적 정보>
이름 : 피카츄
과목 : 응용SW기초기술활용
서술형점수 : 50점
평가자체크리스트점수 : 60점
평균점수 : 55.0점
해당 시험 재평가 응시 대상자입니다
<우리반 성적 정보>
이름 : 라이츄
과목 : 응용SW기초기술활용
서술형점수 : 40점
평가자체크리스트점수 : 80점
평균점수 : 60.0점
해당 시험에 통과하였습니다
<우리반 성적 정보>
이름 : 파이리
과목 : 프로그래밍언어활용
서술형점수 : 60점
평가자체크리스트점수 : 65점
평균점수 : 62.5점
해당 시험에 통과하였습니다

 

 

- 클래스 세터 게터 메소드 구조

 

 

 

 

 

Q. 과제 업로드

다음 정보를 객체로 만들고, 데이터 설정 후 요구사항에 맞게 출력하시오.

학생 성적 정보
| 이름 | 학년 | 국어점수 | 영어점수 | 수학점수 |
| 마리오 | 1 | 90 | 80 | 70 |
| 루이지 | 1 | 85 | 85 | 83 |
| 쿠파 | 3 | 70 | 60 | 55 |

요구 사항
- 정보 출력시 반드시 `총점`, `평균`, `등급`이 나오도록 구현
- `등급`은 다음과 같이 계산합니다
- 90점 이상 100점 이하 : A
- 80점 이상 89점 이하 : B
- 70점 이상 79점 이하 : C
- 70점 미만 : F

 

 

 

- 과제 풀이

package oop.method6;

public class Student {

	// 멤버 변수
	String name;
	int grade;
	int korean;
	int english;
	int math;
	String raking;

	// 세터 메소드
	void setName(String name) {
		this.name = name;
	}

	void setGrade(int grade) {
		if (grade >= 1 && grade <= 3) {
		this.grade = grade;
		}
	}

	void setKorean(int korean) {
		if (korean >= 0 && korean <= 100) {
			this.korean = korean;
		}
	}

	void setEnglish(int english) {
		if (english >= 0 && english <= 100) {
			this.english = english;
		}
	}

	void setMath(int math) {
		if (math >= 0 && math <= 100) {
			this.math = math;
		}
	}

	// 게터 메소드
	String getName() {
		return this.name;
	}

	int getGrade() {
		return this.grade;
	}

	int getKorean() {
		return this.korean;
	}

	int getEnglish() {
		return this.english;
	}

	int getMath() {
		return this.math;
	}

	int getTotal() {
		return this.korean + this.english + this.math;
	}

	float getAverage() {
		return this.getTotal() / 3.0f;
	}

	String getRaking() {
		if (this.getAverage() >= 90) {
			raking = "A";
		} else if (80 <= this.getAverage() && this.getAverage() < 90) {
			raking = "B";
		} else if (70 <= this.getAverage() && this.getAverage() < 80) {
			raking = "C";
		} else {
			raking = "D";
		}
		return this.raking;
	}

	// 멤버 메소드
	void init(String name, int grade, int korean, int english, int math) {
		this.setName(name);
		this.setGrade(grade);
		this.setKorean(korean);
		this.setEnglish(english);
		this.setMath(math);
	}

	// 출력 정보
	void showInfo() {
		System.out.println("<학생 성적 정보>");
		System.out.println("이름 : " + this.name);
		System.out.println("학년 : " + this.grade);
		System.out.println("국어점수 : " + this.korean + "점");
		System.out.println("영어점수 : " + this.english + "점");
		System.out.println("수학점수 : " + this.math + "점");
		System.out.println("총점 : " + this.getTotal() + "점");
		System.out.println("평균 : " + this.getAverage() + "점");
		System.out.println("등급 : " + this.getRaking() + "등급");

	}
}
package oop.method6;

public class Test01 {

	public static void main(String[] args) {

		// 생성
		Student a = new Student();
		Student b = new Student();
		Student c = new Student();

		// 초기화
		a.init("마리오", 1, 90, 80, 70);
		b.init("루이지", 1, 85, 85, 83);
		c.init("쿠파", 3, 70, 60, 55);

		// 테스트
		//a.setGrade(5);
		// a.setMath(-1);
		// b.setMath(101);
		// c.setMath(100);

		// 출력
		a.showInfo();
		b.showInfo();
		c.showInfo();

	}
}

- 정답

<학생 성적 정보>
이름 : 마리오
학년 : 1
국어점수 : 90점
영어점수 : 80점
수학점수 : 70점
총점 : 240점
평균 : 80.0점
등급 : B등급
<학생 성적 정보>
이름 : 루이지
학년 : 1
국어점수 : 85점
영어점수 : 85점
수학점수 : 83점
총점 : 253점
평균 : 84.333336점
등급 : B등급
<학생 성적 정보>
이름 : 쿠파
학년 : 3
국어점수 : 70점
영어점수 : 60점
수학점수 : 55점
총점 : 185점
평균 : 61.666668점
등급 : D등급