/* (실습) List를 사용한 성적 처리
사용클래스명 : StudentVO, StudentListManager - main() 메소드
1. 3명의 학생데이터(성명,국어,영어,수학)를
StudentVO 클래스를 이용해서 만들고
"홍길동", 100, 90, 81
"이순신", 95, 88, 92
"김유신", 90, 87, 77
2. ArrayList 타입의 변수(list)에 저장하고
3. list에 있는 데이터를 사용해서 전체 데이터 화면출력
성명 국어 영어 수학 총점 평균
--------------------------
홍길동 100 90 81 270 90.33
...
4. 김유신 국어 점수를 95 점으로 수정 후 김유신 데이터만 출력
========================================== */
private String name;
private int kor;
private int eng;
private int math;
private int tot;
private double avg;
public StudentVO() {}
public StudentVO(String name, int kor, int eng, int math) {
setName(name);
setKor(kor);
setEng(eng);
setMath(math);
computeTotAvg();
}
public void computeTotAvg() {
this.tot = kor + eng + math;
this.avg = tot * 100 / 3 / 100.0;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getKor() {
return kor;
}
public void setKor(int kor) {
if (kor >= 0 && kor <= 100) {
this.kor = kor;
computeTotAvg();
} else {
System.out.println("[예외] 0~100 범위가 아님");
}
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
if (eng >= 0 && eng <= 100) {
this.eng = eng;
computeTotAvg();
} else {
System.out.println("[예외] 0~100 범위가 아님");
}
}
public int getMath() {
return math;
}
public void setMath(int math) {
if (math >= 0 && math <= 100) {
this.math = math;
computeTotAvg();
} else {
System.out.println("[예외] 0~100 범위가 아님");
}
}
public int getTot() {
return tot;
}
public void setTot(int tot) {
this.tot = tot;
}
public double getAvg() {
return avg;
}
public void setAvg(double avg) {
this.avg = avg;
}
@Override
public String toString() {
return name + "\t" + kor + "\t" + eng + "\t" + math + "\t" + tot + "\t" + avg;
}
StudentVO stu1 = new StudentVO("홍길동", 100, 90, 81);
StudentVO stu2 = new StudentVO("이순신", 95, 88, 92);
StudentVO stu3 = new StudentVO("김유신", 90, 87, 77);
ArrayList<StudentVO> list = new ArrayList<StudentVO>();
list.add(stu1);
list.add(stu2);
list.add(stu3);
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getName().equals("김유신")) {
list.get(i).setKor(95);
System.out.println(list.get(i));
}
}