I used getter and setter method in Subject, and Subject is used in another class Student to instance, but this part generates an error. It seems that the class Student cannot access the setter method because it cannot instantiate the class Subject. If not, I don't know why. And I don't know how to solve it.
package school;
public class Subject {
String subjectName;
int score;
public String getSubjectName() {
return subjectName;
}
public void setSubjectName(String subjectName) {
this.subjectName = subjectName;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
package school;
public class Student {
int studentID;
String studentName;
Subject korea;
Subject math;
public Student(int id, String name){
studentID = id;
studentName =name;
korea = new Subject();
math = new Subject();
}
public void setKorea(String name, int score){
korea.setSubjectName*(name); //this part error
korea.setScore(score); //this part error
}
public void setMath(String name, int score){
math.setSubjectName(name); //this part error
math.setScore(score); //this part error
}
public void showStudentInfo() {
int total = korea.getScore() + math.getScore(); //this part error
System.out.println("학생의 총점은"+ total+"입니다.");
}
}