๋ฐ์ํ
โถ ํ๋ก๊ทธ๋จ ์ ๊ทธ๋ ์ด๋ํ๊ธฐ(์ด์ ๋ง๋ ํ์ ์ฐ์ถ ํ๋ก๊ทธ๋จ์ ๋ฐํ์ผ๋ก!)
โ
*๊ณผ๋ชฉ๊ณผ ํ์ ์ ์ฑ ์ด ์ถ๊ฐ๋๋ ๊ฒฝ์ฐ
โ
Define.java
package utils;
public class Define {
public static final int KOREAN = 1001; // ๊ตญ์ด
public static final int MATH = 2001; // ์ํ
public static final int DANCE = 3001; // ๋ฐฉ์ก ๋์ค
public static final int ENGLISH = 4001; // ์์ด
public static final int AB_TYPE = 0; // ์ผ๋ฐ ๊ณผ๋ชฉ ํ์ ์ฐ์ถ ์ ์ฑ
public static final int SAB_TYPE = 1; // ํ์ ๊ณผ๋ชฉ ํ์ ์ฐ์ถ ์ ์ฑ
public static final int PF_TYPE = 2; // pass/fail ๋ฐฉ์
}
TestMain.java
package test;
import school.School;
import school.Score;
import school.Student;
import school.Subject;
import school.report.GenerateGradeReport;
import utils.Define;
public class TestMain {
School goodSchool = School.getInstance();
Subject korean;
Subject math;
Subject dance;
Subject english;
GenerateGradeReport gradeReport = new GenerateGradeReport();
public static void main(String[] args) {
TestMain test = new TestMain();
test.createSubject();
test.createStudent();
String report = test.gradeReport.getReport(); // ์ฑ์ ๊ฒฐ๊ณผ ์์ฑ
System.out.println(report);
}
public void createSubject() { // ๊ณผ๋ชฉ ์์ฑ
korean = new Subject("๊ตญ์ด", Define.KOREAN);
math = new Subject("์ํ", Define.MATH);
dance = new Subject("๋ฐฉ์ก ๋์ค", Define.DANCE);
english = new Subject("์์ด", Define.ENGLISH);
dance.setGradeType(Define.PF_TYPE); // ํ์ ํ๊ฐ ์ ์ฑ
์ง์
goodSchool.addSubject(korean);
goodSchool.addSubject(math);
goodSchool.addSubject(dance);
goodSchool.addSubject(english);
}
public void createStudent() { // ํ์ ์์ฑ
Student student1 = new Student(181213, "์์ฑ์", korean);
Student student2 = new Student(181518, "์คํํ", math);
Student student3 = new Student(171230, "์ด๋ํธ", korean);
Student student4 = new Student(171255, "์กฐ์ฑ์ฑ", korean);
Student student5 = new Student(171590, "์ตํํ", math);
goodSchool.addStudent(student1); // goodSchool์ ํ์ ์ถ๊ฐ
goodSchool.addStudent(student2);
goodSchool.addStudent(student3);
goodSchool.addStudent(student4);
goodSchool.addStudent(student5);
korean.register(student1); // ๊ตญ์ด ๊ณผ๋ชฉ์ ์๊ฐํ๋ ํ์ ๋ฑ๋ก
korean.register(student2);
korean.register(student3);
korean.register(student4);
korean.register(student5);
math.register(student1); // ์ํ ๊ณผ๋ชฉ์ ์๊ฐํ๋ ํ์ ๋ฑ๋ก
math.register(student2);
math.register(student3);
math.register(student4);
math.register(student5);
dance.register(student1); // ๋ฐฉ์ก ๋์ค๋ฅผ ์๊ฐํ๋ ํ์ ๋ฑ๋ก
dance.register(student2);
dance.register(student3);
english.register(student3); // ์์ด ๊ณผ๋ชฉ์ ์๊ฐํ๋ ํ์ ๋ฑ๋ก
english.register(student4);
english.register(student5);
addScoreForStudent(student1, korean, 95); // ๊ฐ ํ์์ ๊ณผ๋ชฉ ์ ์ ์ถ๊ฐ
addScoreForStudent(student1, math, 56);
addScoreForStudent(student2, korean, 95);
addScoreForStudent(student2, math, 95);
addScoreForStudent(student3, korean, 100);
addScoreForStudent(student3, math, 88);
addScoreForStudent(student3, english, 96);
addScoreForStudent(student4, korean, 89);
addScoreForStudent(student4, math, 95);
addScoreForStudent(student4, english, 80);
addScoreForStudent(student5, korean, 85);
addScoreForStudent(student5, math, 56);
addScoreForStudent(student5, english, 55);
addScoreForStudent(student1, dance, 95);
addScoreForStudent(student2, dance, 85);
addScoreForStudent(student3, dance, 55);
}
public void addScoreForStudent(Student student, Subject subject, int point) { // ๊ณผ๋ชฉ๋ณ ์ ์๋ฅผ ์ถ๊ฐํ๋ ๋ฉ์๋
Score score = new Score(student.getStudentID(), subject, point);
student.addSubjectScore(score);
}
}
PassFailEvaluation.java
package grade;
public class PassFailEvaluation implements GradeEvaluation {
@Override
public String getGrade(int point) {
if (point >= 70)
return "P";
else
return "F";
}
}
GenerateGradeReport.java
package school.report;
import java.util.ArrayList;
import grade.BasicEvaluation;
import grade.GradeEvaluation;
import grade.MajorEvaluation;
import grade.PassFailEvaluation;
import school.School;
import school.Score;
import school.Student;
import school.Subject;
import utils.Define;
public class GenerateGradeReport {
School school = School.getInstance(); // ์ฑ๊ธํค(๊ฐ์ฒด๊ฐ ์์ฑ๋์ด๋ ๊ฐ์ฒด์ ์์ฑ ๊ฐ๋ค์ด ์ ์ง๋จ.)
public static final String TITLE = " ์๊ฐ์ ํ์ \t\t\n";
public static final String HEADER = " ์ด๋ฆ | ํ๋ฒ |ํ์๊ณผ๋ชฉ| ์ ์ \n";
public static final String LINE = "---------------------------\n";
private StringBuffer buffer = new StringBuffer();
public String getReport() {
ArrayList<Subject> subjectList = school.getSubjectList(); // ๋ชจ๋ ๊ณผ๋ชฉ์ ๋ํ ํ์ ์ฐ์ถ
for (Subject subject : subjectList) {
makeHeader(subject);
makeBody(subject);
makeFooter();
}
return buffer.toString(); // String์ผ๋ก ๋ฐํ
}
public void makeHeader(Subject subject) {
buffer.append(GenerateGradeReport.LINE);
buffer.append("\t" + subject.getSubjectName());
buffer.append(GenerateGradeReport.TITLE);
buffer.append(GenerateGradeReport.HEADER);
buffer.append(GenerateGradeReport.LINE);
}
public void makeBody(Subject subject) {
ArrayList<Student> studentList = subject.getStudentList(); // ๊ฐ ๊ณผ๋ชฉ์ ํ์๋ค
for (int i = 0; i < studentList.size(); i++) {
Student student = studentList.get(i);
buffer.append(student.getStudentName());
buffer.append(" | ");
buffer.append(student.getStudentID());
buffer.append(" | ");
buffer.append(student.getMajorSubject().getSubjectName() + "\t");
buffer.append(" | ");
getScoreGrade(student, subject); // ํ์๋ณ ์๊ฐ ๊ณผ๋ชฉ ํ์ ๊ณ์ฐ
buffer.append("\n");
buffer.append(LINE);
}
}
public void getScoreGrade(Student student, Subject Subject) {
ArrayList<Score> scoreList = student.getScoreList();
int majorID = student.getMajorSubject().getSubjectID();
GradeEvaluation[] gradeEvaluation = { new BasicEvaluation(), new MajorEvaluation(),
new PassFailEvaluation() }; // ํ์ ํ๊ฐ ํด๋์ค
for (int i = 0; i < scoreList.size(); i++) { // ํ์์ด ๊ฐ์ง ์ ์๋ฅผ
Score score = scoreList.get(i);
if (score.getSubject().getSubjectID() == Subject.getSubjectID()) { // ํ์ ์ฐ์ถํ ๊ณผ๋ชฉ
String grade;
if (Subject.getGradeType() == Define.PF_TYPE) { // pass/fail ๋ฐฉ์
grade = gradeEvaluation[Define.PF_TYPE].getGrade(score.getPoint());
} else {
if (score.getSubject().getSubjectID() == majorID) // ํ์ ๊ณผ๋ชฉ์ธ ๊ฒฝ์ฐ
grade = gradeEvaluation[Define.SAB_TYPE].getGrade(score.getPoint()); // ํ์ ๊ณผ๋ชฉ ํ์ ํ๊ฐ ๋ฐฉ๋ฒ
else
grade = gradeEvaluation[Define.AB_TYPE].getGrade(score.getPoint()); // ํ์ ๊ณผ๋ชฉ์ด ์๋ ๊ฒฝ์ฐ
buffer.append(score.getPoint());
buffer.append(":");
buffer.append(grade);
buffer.append(" | ");
}
}
}
}
public void makeFooter() {
buffer.append("\n");
}
}
<๊ฒฐ๊ณผ๊ฐ>
-๋จธ์ผ ๋ฐฉ์ก๋์ค ์ ์ ์ ์ถ๋ ฅ์๋ผ?? ๋์ ํ ์์ธ์ ๋ชจ๋ฅด๊ฒ ๋ค
๋ฐ์ํ
'Java' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java-๊ธฐ์ด] ์๊ณ ๋ฆฌ์ฆ ์ค์ต (๋ง๋ฐฉ์ง) (0) | 2021.02.24 |
---|---|
[Java-๊ธฐ์ด] ์๊ณ ๋ฆฌ์ฆ ์ค์ต (๋ฒ๋ธ์ ๋ ฌ) (0) | 2021.02.24 |
[Java-๊ธฐ์ด] ์ค์ต (ํ์ ์ฐ์ถ ํ๋ก๊ทธ๋จ) (0) | 2021.02.24 |
[Java-๊ธฐ์ด] ๊ทธ ์ธ ์ ์ถ๋ ฅ ํด๋์ค (0) | 2021.02.23 |
[Java-๊ธฐ์ด] ์ง๋ ฌํ (0) | 2021.02.23 |
๋๊ธ