일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- PDF병합
- GitFlow
- 코딩테스트
- Hibernate
- Git
- springboot
- spring jpa
- Visual Basic
- PDFBOX
- 스프링부트 쇼핑몰 프로젝트
- 커밋 컨벤션
- 테킷
- 프로그래머스
- 연관관계
- 값 타입
- VB
- orm
- JPA
- 체인호출
- DOCS
- 제작기
- 알고리즘
- Java
- break-label
- querydsl
- 멋쟁이사자처럼
- spring
- responsepart
- 부트캠프
- 반복문 탈출
Archives
- Today
- Total
섭섭한 개발일지
[명언게시판] level 6 본문
구현 요구사항
== 명언 앱 ==
명령) 등록
명언 : 현재를 사랑하라.
작가 : 작자미상
1번 명언이 등록되었습니다.
명령) 등록
명언 : 현재를 사랑하라.
작가 : 작자미상
2번 명언이 등록되었습니다.
명령) 목록
번호 / 작가 / 명언
----------------------
2 / 작자미상 / 과거에 집착하지 마라.
1 / 작자미상 / 현재를 사랑하라.
명령) 삭제?id=1
1번 명언이 삭제되었습니다.
명령) 종료
: 명언 삭제에 대한 기능 구현이다.
삭제할 명언의 고유번호를 입력하면 되지만 명령이 "삭제?id={no}" 이기에 이부분에서 no을 얻기 위해서는 split을 처리를 해야할 것 같다.
입력에 대한 오류 처리도 있어야 하겠지만 level 7에서 예외처리를 진행하는 것이 있으므로 여기서는 건너뛴다.
구현
// main
public class Application {
public static void main(String[] args) {
SayingRepository repo = SayingRepository.getInstance();
Input input = new Input();
Output output = new Output();
while (true) {
System.out.print("명령) ");
String request = InputView.read();
if (request.equals("등록")) {
Saying saying = input.addSaying(new Saying());
repo.save(saying);
output.printAddSaying(saying);
}
if (request.equals("목록")) {
output.printSayings(repo.findAll());
}
if (request.startsWith("삭제?id=")) {
Long id = input.deleteSaying(request);
repo.delete(id);
output.printDelSaying(id);
}
if (request.equals("종료")) {
break;
}
}
}
}
// repository : 추가한 코드만 삽입
public void delete(Long id) {
sayings.remove(id);
}
// input
public Long deleteSaying(String input) {
Long deleteId = Long.parseLong(input.split("=")[1]);
return deleteId;
}
// output
public void printDelSaying(Long id) {
System.out.println(id + " 번 명언이 삭제되었습니다.");
}
'멋쟁이사자처럼 > Project' 카테고리의 다른 글
[명언게시판] level 5 (0) | 2023.10.27 |
---|---|
[명언게시판] level 4 (0) | 2023.10.27 |
[명언게시판] level 3 (0) | 2023.10.27 |
[명언게시판] level 2 (0) | 2023.10.27 |
[명언게시판] level 1 (0) | 2023.10.27 |
Comments