클래스
- 객체 추출
- 클래스 설계(UML 활용)(깃마인드 활용]) OR UMLet
Main
package mycom.mytest;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
StudentInfo s1 = new StudentInfo(1, "홍길동", 88, 56, 82);
s1.display();
StudentInfo s2 = new StudentInfo(2, "김길동", 82, 89, 95);
s2.display();
}
}
Class
package mycom.mytest;
public class StudentInfo {
// 속성 = 인스턴스 변수
private int sid;
private String sname;
private int kor;
private int math;
private int eng;
private int total;
public StudentInfo() {
}
// 다형성 - 함수를 한 객체 안에 여러개 생성할 수 있음 (메소드 Overloading)
// 생성자 자동 생성 / Source - Generate Using Fields
public StudentInfo(int sid, String sname, int kor, int math, int eng) {
super();
this.sid = sid;
this.sname = sname;
this.kor = kor;
this.math = math;
this.eng = eng;
this.total = this.kor + this.math + this.eng;
}
public void display() {
System.out.println(this.sid + "\t" + this.sname + "\t" + this.kor + "\t" + this.eng + "\t" + this.math + "\t" + this.total);
}
// setter, getter 함수
public int getKor() {
return this.kor;
}
public void set(int kor) {
if(kor >= 0 && kor <= 100) {
this.kor = kor;
}
}
}