728x90
SMALL
- Application
public class Application {
public static void main(String[] args) {
new TodoApplication();
}
}
- TodoApplication
import java.time.LocalDateTime;
import java.util.Scanner;
public class TodoApplication {
Scanner in = new Scanner(System.in);
TodoService todoService = new TodoService();
public TodoApplication() {
run();
}
public void run() {
renderMenu();
int selectedAction = chooseMenu();
System.out.println(selectedAction);
act(selectedAction);
}
private void act(int selectedAction) {
switch (selectedAction) {
case 1:
renderAddingTodo();
break;
case 2:
break;
case 3:
break;
default:
System.out.println("망");
break;
}
}
private void renderAddingTodo() {
System.out.println("1.할일을 추가해주세요");
System.out.println("할일추가");
String message = in.next();
System.out.println(message);
Todo todo = new Todo(message, LocalDateTime.now());
todoService.addTodo(todo);
}
private int chooseMenu() {
System.out.println("선택 >");
return in.nextInt();
}
private void renderMenu() {
System.out.println("1.할일 추가");
System.out.println("2.할일 목록");
System.out.println("3.할일 삭제");
}
}
- Todo
import java.time.LocalDateTime;
public class Todo {
private final String message;
private final LocalDateTime writtenDate;
public Todo(String message, LocalDateTime writtenDate) {
this.message = message;
this.writtenDate = writtenDate;
}
}
- TodoService
public class TodoService {
private TodoRepository repository = new InMemoryTodoRepository();
public void addTodo(Todo todo) {
repository.save(todo);
}
}
- InMemoryTodoRepository
import java.util.ArrayList;
import java.util.List;
public class InMemoryTodoRepository implements TodoRepository {
List<Todo> list = new ArrayList<>();
@Override
public void save(Todo todo) {
list.add(todo);
}
}
- TodoRepository
public interface TodoRepository {
void save(Todo todo);
}
728x90
LIST
'JAVA > Project' 카테고리의 다른 글
전화번호부 검색기능 (0) | 2020.10.21 |
---|---|
전화번호부 검색, 출력 메소드 (0) | 2020.10.21 |
댓글