From d8d590a7430515cf890371435120fa49d62ea930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=9A=B8?= Date: Mon, 26 Jun 2023 09:23:47 +0900 Subject: [PATCH 1/2] Update Main.java --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 51147df..0223032 100644 --- a/src/Main.java +++ b/src/Main.java @@ -5,7 +5,7 @@ public static void main(String[] args) { // 부산소프트웨어마이스터고등학교를 생성합니다. // 밤돌중학교를 다니고 있는 이밤돌 학생을 생성합니다. - +ㅁㅇㄹㅁㅇ // 곰돌중학교를 다니고 있는 금곰돌 학생을 생성합니다. From 2d8ac0bcc98c217580604d7ae55e748ad78990bc Mon Sep 17 00:00:00 2001 From: gimhanul Date: Tue, 27 Jun 2023 09:52:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?ADD=20::=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 +- src/Main.java | 45 +++++++++-- .../AlreadySubmittedException.java | 4 + src/application/Application.java | 80 +++++++++++++++++++ src/application/Certificate.java | 18 +++++ src/application/State.java | 19 +++++ src/school/School.java | 67 ++++++++++++++++ src/student/Student.java | 72 +++++++++++++++++ 8 files changed, 301 insertions(+), 12 deletions(-) create mode 100644 src/application/AlreadySubmittedException.java create mode 100644 src/application/Application.java create mode 100644 src/application/Certificate.java create mode 100644 src/application/State.java create mode 100644 src/school/School.java create mode 100644 src/student/Student.java diff --git a/README.md b/README.md index 1de89a4..9aee329 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## 0️⃣ 과제 안내 +## 0️⃣ 과제 안내 > **원서 접수** 기능 구현하기 @@ -20,7 +20,7 @@
-## 1️⃣ 제출 방법 +## 1️⃣ 제출 방법 1. 이 레포지토리를 포크합니다. 2. 본인의 이름으로 브랜치를 만듭니다. (예시: hanul) @@ -36,7 +36,7 @@
-## 2️⃣ 평가 기준 +## 2️⃣ 평가 기준 | 항목 | 내용 | 비율 | | --- | --- | --- | @@ -49,7 +49,7 @@
-## 3️⃣ 커밋 메시지 규칙 +## 3️⃣ 커밋 메시지 규칙 ### 형식 ``` diff --git a/src/Main.java b/src/Main.java index 0223032..f0054fe 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,45 +1,74 @@ +import application.Certificate; +import school.School; +import student.Student; + +import java.util.List; + public class Main { public static void main(String[] args) { // TODO-0 데이터 생성 // 부산소프트웨어마이스터고등학교를 생성합니다. + School bssm = new School("부산소프트웨어마이스터고등학교"); // 밤돌중학교를 다니고 있는 이밤돌 학생을 생성합니다. -ㅁㅇㄹㅁㅇ + Student lee = new Student( + "이밤돌", + "010-1234-5678", + new School("밤돌중학교"), + List.of(70, 68, 91), + List.of(0, 3, 0), + List.of() + ); + + // 곰돌중학교를 다니고 있는 금곰돌 학생을 생성합니다. + Student gold = new Student( + "금곰돌", + "010-1234-4231", + new School("곰돌중학교"), + List.of(100, 95, 100), + List.of(0, 0, 0), + List.of(Certificate.USEFUL_COMPUTER_SKILL_LEVEL_1) + ); // TODO-1 이밤돌 학생 원서 // 이밤돌 학생이 부산소프트웨어마이스터고등학교에 낼 원서를 작성합니다. + lee.writeApplication(bssm); // 이밤돌 학생이 원서를 제출합니다. - + lee.submitApplication(); // TODO-2 금곰돌 학생 원서 // 금곰돌 학생이 부산소프트웨어마이스터고등학교에 낼 원서를 작성합니다. + gold.writeApplication(bssm); // 금곰돌 학생이 원서를 제출합니다. - - + gold.submitApplication(); + // TODO-3 이밤돌 학생 원서 재제출 // 이밤돌 학생이 부산소프트웨어마이스터고등학교에 낼 원서를 작성합니다. - + lee.writeApplication(bssm); + // 이밤돌 학생이 원서를 제출합니다. // 원서는 정상적으로 처리하지 않고, 한 번만 제출할 수 있다는 메시지를 출력합니다. - + lee.submitApplication(); // TODO-4 원서 조회 // 제출한 모든 원서를 점수 순을 조회합니다. - + bssm.printApplicationByScore(); // TODO-5 합불 여부 입력 // 자유롭게 기준을 세워서 그 기준에 따라 이밤돌 학생은 탈락으로, 금곰돌 학생은 합격으로 처리합니다. - + bssm.handleApplication(); // TODO-6 자신의 원서 상태 조회 // 이밤돌 학생이 본인의 원서 상태를 조회합니다. + lee.printApplicationState(); // 금곰돌 학생이 본인의 원서 상태를 조회합니다. + gold.printApplicationState(); } } diff --git a/src/application/AlreadySubmittedException.java b/src/application/AlreadySubmittedException.java new file mode 100644 index 0000000..f491723 --- /dev/null +++ b/src/application/AlreadySubmittedException.java @@ -0,0 +1,4 @@ +package application; + +public class AlreadySubmittedException extends RuntimeException { +} diff --git a/src/application/Application.java b/src/application/Application.java new file mode 100644 index 0000000..1402f59 --- /dev/null +++ b/src/application/Application.java @@ -0,0 +1,80 @@ +package application; + +import school.School; +import student.Student; + +import java.util.List; + +public class Application { + + private int gradeScore; + private int attendanceScore; + private int bonusScore; + private State state; + private Student applicant; + private School targetSchool; + + public void submit() { + targetSchool.receiveApplication(this); + } + + public Application(Student writer, School targetSchool) { + this.gradeScore = calculateGradeScore(writer.getGradeList()); + this.attendanceScore = calculateAttendanceScore(writer.getAttendanceList()); + this.bonusScore = calculateBonusScore(writer.getCertificateList()); + this.applicant = writer; + this.targetSchool = targetSchool; + this.state = State.DRAFT; + } + + private int calculateGradeScore(List gradeList) { + return gradeList.stream() + .mapToInt(Integer::intValue) + .sum(); + } + + private int calculateAttendanceScore(List attendanceList) { + return 30 - attendanceList.stream() + .mapToInt(Integer::intValue) + .sum(); + } + + private int calculateBonusScore(List certificateList) { + return certificateList.stream() + .mapToInt(Certificate::getScore) + .sum(); + } + + public void submitted() { + this.state = State.SUBMITTED; + } + + public void pass() { + this.state = State.PASSED; + } + + public void fail() { + this.state = State.FAILED; + } + + public Student getApplicant() { + return applicant; + } + + public int getTotalScore() { + return gradeScore + attendanceScore + bonusScore; + } + + public String getState() { + return state.getDescription() + "되었습니다."; + } + + @Override + public String toString() { + return String.format("| %s | %s | %s | %d |", + applicant.getName(), + applicant.getPhoneNumber(), + applicant.getSchool().getName(), + getTotalScore()); + } +} diff --git a/src/application/Certificate.java b/src/application/Certificate.java new file mode 100644 index 0000000..d0f12c0 --- /dev/null +++ b/src/application/Certificate.java @@ -0,0 +1,18 @@ +package application; + +public enum Certificate { + USEFUL_COMPUTER_SKILL_LEVEL_1(3), + USEFUL_COMPUTER_SKILL_LEVEL_2(2), + USEFUL_COMPUTER_SKILL_LEVEL_3(1) + ; + + private final int score; + + Certificate(int score) { + this.score = score; + } + + public int getScore() { + return score; + } +} diff --git a/src/application/State.java b/src/application/State.java new file mode 100644 index 0000000..c2c618e --- /dev/null +++ b/src/application/State.java @@ -0,0 +1,19 @@ +package application; + +public enum State { + DRAFT("작성"), + SUBMITTED("제출"), + PASSED("합격"), + FAILED("탈락") + ; + + private final String description; + + State(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } +} diff --git a/src/school/School.java b/src/school/School.java new file mode 100644 index 0000000..12d0402 --- /dev/null +++ b/src/school/School.java @@ -0,0 +1,67 @@ +package school; + +import application.AlreadySubmittedException; +import application.Application; + +import java.util.ArrayList; +import java.util.List; + +public class School { + + private final String name; + private final List applicationList = new ArrayList<>(); + + public School(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void receiveApplication(Application application) { + try { + validateApplication(application); + applicationList.add(application); + application.submitted(); + returnApplication(application); + System.out.println("원서가 정상적으로 제출되었습니다."); + } catch (AlreadySubmittedException e){ + System.out.println("원서는 한 번만 제출할 수 있습니다."); + } + } + + private void returnApplication(Application application) { + application.getApplicant().receiveApplication(application); + } + + private void validateApplication(Application application) { + for (Application submmitedApplication : applicationList) { + if (submmitedApplication.getApplicant().equals(application.getApplicant())) { + throw new AlreadySubmittedException(); + } + } + } + + public void printApplicationByScore() { + System.out.println(); + System.out.println("< " + name + " 원서 접수 현황 >"); + System.out.println("=========================================="); + System.out.println("| 이 름 | 전화번호 | 출신중학교 | 총점 |"); + System.out.println("------------------------------------------"); + applicationList.stream() + .sorted((a1, a2) -> a2.getTotalScore() - a1.getTotalScore()) + .forEach(System.out::println); + System.out.println("=========================================="); + System.out.println(); + } + + public void handleApplication() { + applicationList.stream() + .filter(application -> application.getTotalScore() >= 300) + .forEach(Application::pass); + applicationList.stream() + .filter(application -> application.getTotalScore() < 300) + .forEach(Application::fail); + } +} diff --git a/src/student/Student.java b/src/student/Student.java new file mode 100644 index 0000000..85d4bf5 --- /dev/null +++ b/src/student/Student.java @@ -0,0 +1,72 @@ +package student; + +import application.Application; +import application.Certificate; +import school.School; + +import java.util.List; + +public class Student { + + private final String name; + private final String phoneNumber; + private final School school; + + private final List gradeList; + private final List attendanceList; + private final List certificateList; + private Application application; + private Application writtenApplication; + + public Student(String name, String phoneNumber, School school, List gradeList, List attendanceList, List certificateList) { + this.name = name; + this.phoneNumber = phoneNumber; + this.school = school; + this.gradeList = gradeList; + this.attendanceList = attendanceList; + this.certificateList = certificateList; + } + + public void writeApplication(School targetSchool) { + this.writtenApplication = new Application( + this, + targetSchool + ); + } + + public void submitApplication() { + writtenApplication.submit(); + } + + public List getGradeList() { + return gradeList; + } + + public List getAttendanceList() { + return attendanceList; + } + + public List getCertificateList() { + return certificateList; + } + + public String getName() { + return name; + } + + public String getPhoneNumber() { + return phoneNumber; + } + + public School getSchool() { + return school; + } + + public void printApplicationState() { + System.out.println(application.getState()); + } + + public void receiveApplication(Application application) { + this.application = application; + } +}