Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hanul #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0️⃣ 과제 안내
## 0️⃣ 과제 안내

> **원서 접수** 기능 구현하기

Expand All @@ -20,7 +20,7 @@

<br>

## 1️⃣ 제출 방법
## 1️⃣ 제출 방법

1. 이 레포지토리를 포크합니다.
2. 본인의 이름으로 브랜치를 만듭니다. (예시: hanul)
Expand All @@ -36,7 +36,7 @@

<br>

## 2️⃣ 평가 기준
## 2️⃣ 평가 기준

| 항목 | 내용 | 비율 |
| --- | --- | --- |
Expand All @@ -49,7 +49,7 @@
<br>


## 3️⃣ 커밋 메시지 규칙
## 3️⃣ 커밋 메시지 규칙

### 형식
```
Expand Down
43 changes: 36 additions & 7 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -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();

}
}
4 changes: 4 additions & 0 deletions src/application/AlreadySubmittedException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package application;

public class AlreadySubmittedException extends RuntimeException {
}
80 changes: 80 additions & 0 deletions src/application/Application.java
Original file line number Diff line number Diff line change
@@ -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<Integer> gradeList) {
return gradeList.stream()
.mapToInt(Integer::intValue)
.sum();
}

private int calculateAttendanceScore(List<Integer> attendanceList) {
return 30 - attendanceList.stream()
.mapToInt(Integer::intValue)
.sum();
}

private int calculateBonusScore(List<Certificate> 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());
}
}
18 changes: 18 additions & 0 deletions src/application/Certificate.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 19 additions & 0 deletions src/application/State.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
67 changes: 67 additions & 0 deletions src/school/School.java
Original file line number Diff line number Diff line change
@@ -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<Application> 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);
}
}
72 changes: 72 additions & 0 deletions src/student/Student.java
Original file line number Diff line number Diff line change
@@ -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<Integer> gradeList;
private final List<Integer> attendanceList;
private final List<Certificate> certificateList;
private Application application;
private Application writtenApplication;

public Student(String name, String phoneNumber, School school, List<Integer> gradeList, List<Integer> attendanceList, List<Certificate> 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<Integer> getGradeList() {
return gradeList;
}

public List<Integer> getAttendanceList() {
return attendanceList;
}

public List<Certificate> 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;
}
}