package ch09;
public class Subject {
String subjectName;
int score;
int subjectId;
}
package ch09;
public class Student {
int studentId;
String studentName;
Subject korea;
Subject math;
public Student(int studentId, String studentName) {
this.studentId = studentId;
this.studentName = studentName;
korea = new Subject();
math = new Subject();
}
public void setKoreaSubject(String name, int score) {
korea.subjectName = name;
korea.score = score;
}
public void setMathSubject(String name, int score) {
math.subjectName = name;
math.score = score;
}
public void showScore() {
int total = korea.score + math.score;
System.out.println(studentName + "학생의 총점은 " + total + "점 입니다.");
}
}
package ch09;
public class SubjectTest {
public static void main(String[] args) {
Student student = new Student(1, "Yoon");
student.setKoreaSubject("국어", 100);
student.setMathSubject("수학", 90);
Student studentKim = new Student(2, "Kim");
studentKim.setKoreaSubject("국어", 50);
studentKim.setMathSubject("수학", 40);
student.showScore();
studentKim.showScore();
}
}
Yoon학생의 총점은 190점 입니다.
Kim학생의 총점은 90점 입니다.