Skip to content
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
30 changes: 30 additions & 0 deletions docs/how-to-solve.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
### 미션 해결 전략
#### 1. 본인이 이해하고 구현한 내용에 기반해 '다른 근무자와 순서를 바꿔야 하는 경우'를 자신만의 예시를 들어 설명하세요. (필수)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 경우 예외 처리가 안되어 있네요.

"4,월",
"a,b,c,d,e",
"a,b,c,d,e"

우선 평일순번과 주말순번을 돌다보면 겹치는 상황이 발생할 것 이고, 요구사항에 따라 다음 순서의 근무자와 교체 후 당번을 만들면 된다고 생각했습니다.
가장 쉬운 예시로
휴일이 없는 4,월 을 기준으로

4,월
평일 비상 근무 순번대로 사원 닉네임을 입력하세요> 준팍,도밥,고니,수아,루루,글로,솔로스타
휴일 비상 근무 순번대로 사원 닉네임을 입력하세요> 준팍,도밥,고니,수아,루루,글로,솔로스타

이러한 형태로 입력하게 되면
1. 처음 평일 순번 준팍 ~ 루루
2. 처음 주말 순번 준팍, 도밥
3. 그 다음 평일 순번 글로 ~ 고니
4. 금요일이 고니가 되는데 고니는 토요일순번이 되어버려서 근무가 겹칩니다.
5. 그래서 이때 고니와 수아의 주말순번을 변경하고
4월 1일 월 준팍
4월 2일 화 도밥
4월 3일 수 고니
4월 4일 목 수아
4월 5일 금 루루
4월 6일 토 준팍
4월 7일 일 도밥
4월 8일 월 글로
4월 9일 화 솔로스타
4월 10일 수 준팍
4월 11일 목 도밥
4월 12일 금 고니
4월 13일 토 수아 -> 원래 고니 순번
4월 14일 일 고니 -> 원래 수아 순번
4월 15일 월 수아
위와 같은 형태가 됩니다.
주말에서 평일이 넘어가는 경우도 동일하게 평일순번 위치를 변경하면 문제를 해결할 수 있습니다.

#### 2. 요구사항에서 제시한 앞의 날짜부터 순서를 변경하는 방법 외에 다른 방법이 있다면 어떤 방식이 있는지, 이 방법은 기존에 제시된 방식과 비교해 어떤 차이가 있는지 설명하세요. (선택)
12 changes: 11 additions & 1 deletion src/main/java/oncall/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package oncall;

import oncall.controller.CustomController;
import oncall.service.CustomService;
import oncall.view.InputView;
import oncall.view.OutputView;

public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
InputView inputView = new InputView();
OutputView outputView = new OutputView();
CustomService customService = new CustomService();

CustomController controller = new CustomController(inputView, outputView, customService);
controller.run();
}
}
29 changes: 29 additions & 0 deletions src/main/java/oncall/config/Holidays.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package oncall.config;

public enum Holidays {
NEW_YEARS_DAY(1, 1), // 1월 1일
INDEPENDENCE_DAY(3, 1), // 3월 1일
CHILDRENS_DAY(5, 5), // 5월 5일
MEMORIAL_DAY(6, 6), // 6월 6일
LIBERATION_DAY(8, 15), // 8월 15일
NATIONAL_FOUNDATION_DAY(10, 3), // 10월 3일
HANGUL_DAY(10, 9), // 10월 9일
CHRISTMAS_DAY(12, 25); // 12월 25일

private final int month;
private final int day;

// Constructor
Holidays(int month, int day) {
this.month = month;
this.day = day;
}

public int getMonth() {
return month;
}

public int getDay() {
return day;
}
}
44 changes: 44 additions & 0 deletions src/main/java/oncall/controller/CustomController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package oncall.controller;

import java.util.List;
import oncall.domain.CombinedRoster;
import oncall.domain.MonthAndDayOfWeek;
import oncall.domain.MonthlyRoster;
import oncall.domain.Roster;
import oncall.domain.Worker;
import oncall.service.CustomService;
import oncall.view.InputView;
import oncall.view.OutputView;

public class CustomController extends ExceptionLoopController{
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

컨벤션 통일위해 린트 설정하고 가는걸 추천해요.

private final InputView input;
private final OutputView output;
private final CustomService service;

public CustomController(InputView input, OutputView output, CustomService service) {
this.input = input;
this.output = output;
this.service = service;
}

public void run() {
MonthAndDayOfWeek monthAndDayOfWeek = repeatUntilValid(this::getMonthAndDayOfWeek);
CombinedRoster combinedRoster = repeatUntilValid(this::getRoster);
List<MonthlyRoster> monthlyRoster = service.makeMonthlyRoster(monthAndDayOfWeek, combinedRoster);
output.printMonthlyRoster(monthlyRoster);
}

private MonthAndDayOfWeek getMonthAndDayOfWeek() {
output.printGetMonthDayOfWeek();
return input.getMonthDayOfWeek();
}

private CombinedRoster getRoster() {
output.printGetWeekdayRoster();
Roster weekdayRoster = input.getRoster();
output.printGetWeekendRoster();
Roster weekendRoster = input.getRoster();

return new CombinedRoster(weekdayRoster, weekendRoster);
}
}
16 changes: 16 additions & 0 deletions src/main/java/oncall/controller/ExceptionLoopController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package oncall.controller;

import java.util.function.Supplier;
import oncall.exception.CustomException;

public abstract class ExceptionLoopController {
protected <T> T repeatUntilValid(Supplier<T> function) {
while(true) {
try {
return function.get();
} catch (CustomException e) {
System.out.println(e.getMessage());
}
}
}
}
34 changes: 34 additions & 0 deletions src/main/java/oncall/domain/CombinedRoster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package oncall.domain;

import java.util.List;
import oncall.exception.IllegalInputException;

public class CombinedRoster {
private final Roster weekdayRoster;
private final Roster weekendRoster;

public CombinedRoster(Roster weekdayRoster, Roster weekendRoster) {
validate(weekdayRoster, weekendRoster);
this.weekdayRoster = weekdayRoster;
this.weekendRoster = weekendRoster;
}

private void validate(Roster weekdayRoster, Roster weekendRoster) {
List<Worker> weekdayWorkers = weekdayRoster.getWorkers();
List<Worker> weekendWorkers = weekendRoster.getWorkers();

if(weekdayWorkers.size() != weekendWorkers.size()){
throw new IllegalInputException();
}
// 중복 검사 로직은 나중에
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Roster에 중복 검사 로직이 구현되지 않았나요?

}

public Roster getWeekdayRoster() {
return weekdayRoster;
}

public Roster getWeekendRoster() {
return weekendRoster;
}

}
36 changes: 36 additions & 0 deletions src/main/java/oncall/domain/MonthAndDayOfWeek.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package oncall.domain;

import java.time.DayOfWeek;
import java.time.Month;
import java.time.format.TextStyle;
import java.util.Locale;

public class MonthAndDayOfWeek {
private final Month month;
private final DayOfWeek dayOfWeek;

public MonthAndDayOfWeek(Month month, DayOfWeek dayOfWeek) {
this.month = month;
this.dayOfWeek = dayOfWeek;
}

public int getMonthNumber(){
return month.getValue();
}

public int getLastDay() {
return month.minLength();
}

public int getDayOfWeekNumber() {
return dayOfWeek.getValue();
}

public String getDayOfWeekName() {
return dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.KOREAN);
}

public DayOfWeek getDayOfWeek() {
return dayOfWeek;
}
}
30 changes: 30 additions & 0 deletions src/main/java/oncall/domain/MonthlyRoster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package oncall.domain;

public class MonthlyRoster {
private final int month;
private final int day;
private final String dayOfWeek;
private final String name;
private final boolean holiday;

public MonthlyRoster(int month, int day, String dayOfWeek, String name, boolean holiday) {
this.month = month;
this.day = day;
this.dayOfWeek = dayOfWeek;
this.name = name;
this.holiday = holiday;
}

@Override
public String toString() {
return String.valueOf(month) + "월 " + String.valueOf(day) + "일 " + dayOfWeek + isHoliday() + name;
}

private String isHoliday() {
//주말은 아님
if (holiday && !(dayOfWeek.equals("토") || dayOfWeek.equals("일"))) {
return "(휴일) ";
}
return " ";
}
}
52 changes: 52 additions & 0 deletions src/main/java/oncall/domain/Roster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package oncall.domain;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import oncall.exception.IllegalInputException;

public class Roster {
private final List<Worker> workers;
private static final int WORKERS_MIN_SIZE = 5;
private static final int WORKERS_MAX_SIZE = 35;


public Roster(List<Worker> workers) {
validate(workers);
this.workers = workers;
}

private void validate(List<Worker> workers) {
if (workers.size() < WORKERS_MIN_SIZE || workers.size() > WORKERS_MAX_SIZE) {
throw new IllegalInputException();
}
checkDuplicate(workers);
}

private void checkDuplicate(List<Worker> workers) {
Set<String> names = new HashSet<>();
for (Worker w : workers) {
names.add(w.getName());
}
if (workers.size() != names.size()) {
throw new IllegalInputException();
}
}

public List<Worker> getWorkers() {
return workers;
}

public String getWorkerNameByIndex(int i) {
return workers.get(i).getName();
}

public void swapRoster(int i) {
Collections.swap(workers, i, i + 1);
}

public int getRosterSize() {
return workers.size();
}
}
24 changes: 24 additions & 0 deletions src/main/java/oncall/domain/Worker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package oncall.domain;

import oncall.exception.IllegalNameException;

public class Worker {
private static final int NAME_LENGTH = 5;

private final String name;

public Worker(String name){
validate(name);
this.name = name;
}

private void validate(String name) {
if(name.length() > NAME_LENGTH){
throw new IllegalNameException();
}
}

public String getName() {
return name;
}
}
9 changes: 9 additions & 0 deletions src/main/java/oncall/exception/CustomException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package oncall.exception;

public class CustomException extends IllegalArgumentException{
private static final String ERROR_PREFIX = "[ERROR] ";

CustomException(String message){
super(ERROR_PREFIX + message);
}
}
7 changes: 7 additions & 0 deletions src/main/java/oncall/exception/IllegalInputException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package oncall.exception;

public class IllegalInputException extends CustomException {
public IllegalInputException() {
super("유효하지 않은 입력 값입니다. 다시 입력해 주세요.");
}
}
7 changes: 7 additions & 0 deletions src/main/java/oncall/exception/IllegalNameException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package oncall.exception;

public class IllegalNameException extends CustomException {
public IllegalNameException() {
super("이름이 5자 초과입니다. 다시 입력해 주세요.");
}
}
Loading