1. 문제 정의
HongSchool 학교가 있습니다. 이 학교에는 5명의 학생들이 수업을 듣습니다. 과목은 국어와 수학이 있고, 각 학생은 두 과목을 모두 수강합니다. 학교에 전공은 컴퓨터공학과 국어국문학 두 가지가 있습니다. 컴퓨터공학과 학생은 수학이 필수과목이고, 국어국문학과 학생은 국어가 필수 과목입니다.각 학생별로 한 개의 전공을 선택합니다.
이번 학기 각 학생의 성적은 다음과 같습니다.
2. 요구되는 결과 화면
1. E-R 다이어그램
2. Student 클래스 구현
public class Student {
private int studentId;
private String studentName;
private Subject majorSubject;
private ArrayList<Subject> studentSubject;
private ArrayList<Score> scoreList;
public Student(int studentId, String studentName, Subject majorSubject) {
this.studentId = studentId;
this.studentName = studentName;
this.majorSubject = majorSubject;
scoreList = new ArrayList<Score>();
}
public void addStudentScore(Score score) {
scoreList.add(score);
}
public int getStudentId() {
return studentId;
}
public void setStudentId(int studentId) {
this.studentId = studentId;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public Subject getMajorSubject() {
return majorSubject;
}
public void setMajorSubject(Subject majorSubject) {
this.majorSubject = majorSubject;
}
public ArrayList<Subject> getStudentSubject() {
return studentSubject;
}
public void setStudentSubject(ArrayList<Subject> studentSubject) {
this.studentSubject = studentSubject;
}
public ArrayList<Score> getScoreList() {
return scoreList;
}
public void setScoreList(ArrayList<Score> scoreList) {
this.scoreList = scoreList;
}
}
3. Subject 클래스 구현
public class Subject {
private String subjectName;
private int subjectId;
private int gradeType;
private ArrayList<Student> studentList;
public Subject(String subjectName, int subjectId, int gradeType) {
this.subjectName = subjectName;
this.subjectId = subjectId;
this.gradeType = gradeType;
studentList = new ArrayList<Student>();
}
public void register(Student student) {
studentList.add(student);
}
public String getSubjectName() {
return subjectName;
}
public void setSubjectName(String subjectName) {
this.subjectName = subjectName;
}
public int getSubjectId() {
return subjectId;
}
public void setSubjectId(int subjectId) {
this.subjectId = subjectId;
}
public int getGradeType() {
return gradeType;
}
public void setGradeType(int gradeType) {
this.gradeType = gradeType;
}
public ArrayList<Student> getStudentList() {
return studentList;
}
public void setStudentList(ArrayList<Student> studentList) {
this.studentList = studentList;
}
}
4. Score 클래스 구현
public class Score {
private int studentId;
private Subject subject;
private int point;
public Score(int studentId, Subject subject, int point) {
this.studentId = studentId;
this.subject = subject;
this.point = point;
}
public int getStudentId() {
return studentId;
}
public void setStudentId(int studentId) {
this.studentId = studentId;
}
public Subject getSubject() {
return subject;
}
public void setSubject(Subject subject) {
this.subject = subject;
}
public int getPoint() {
return point;
}
public void setPoint(int point) {
this.point = point;
}
}
5. School 클래스 구현
public class School {
public static School instance = new School();
private ArrayList<Student> studentList ;
private ArrayList<Subject> subjectList ;
private School() {
studentList = new ArrayList<Student>();
subjectList = new ArrayList<Subject>();
}
public void addStudent(Student student) {
studentList.add(student);
}
public void addSubject(Subject subject) {
subjectList.add(subject);
}
public static School getInstance() {
return instance;
}
public static void setInstance(School instance) {
School.instance = instance;
}
public ArrayList<Student> getStudentList() {
return studentList;
}
public void setStudentList(ArrayList<Student> studentList) {
this.studentList = studentList;
}
public ArrayList<Subject> getSubjectList() {
return subjectList;
}
public void setSubjectList(ArrayList<Subject> subjectList) {
this.subjectList = subjectList;
}
}
6. Define 클래스 구현
public class Define {
public static final int KOREAN = 1001; //국어
public static final int MATH = 2001; //수학
public static final int AB_TYPE = 0; // A, B, C
public static final int SAB_TYPE = 1; // S, A, B, c
public static final int PF_TYPE = 2; // P, F
}