-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoService.java
More file actions
123 lines (97 loc) · 5.22 KB
/
Copy pathMemoService.java
File metadata and controls
123 lines (97 loc) · 5.22 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package memo;
import java.text.NumberFormat;
import java.util.Scanner;
public class MemoService {
void run(){
MemoList memoList = new MemoList();
while(true){
showMenu();
// 사용자에게 1~5번 사이 숫자를 받는다.
Scanner s = new Scanner(System.in);
int userInputNumber = -1;
try {
userInputNumber = Integer.parseInt(s.nextLine());
} catch(NumberFormatException e){
System.out.println("잘못된 입력입니다. 1~5사이 숫자로 다시 시도해주세요");
}
switch(userInputNumber){
case 1: // 1. 메모 쓰기
System.out.println("이름을 입력해주세요.");
String name = s.nextLine(); // 유저이름
System.out.println("비밀번호를 입력해주세요.");
String password = s.nextLine();
System.out.println("메모 내용을 자유롭게 작성해주세요");
String content = s.nextLine();
memoList.addMemo(name, password, content);
break;
case 2: // 2. 메모 목록보기
memoList.showAllMemos();
break;
case 3: // 3. 메모 수정하기
System.out.println("수정할 글 번호를 입력해주세요.");
int memoNumUp = -1; // 초기값 설정. 글 번호에는
// memoNumUp => 업데이트 시키고 싶은 글번호
try {
memoNumUp = Integer.parseInt(s.nextLine());
}catch(NumberFormatException e){ // 정수가 아닌 이상한 값을 입력할 때.
System.out.println("잘못된 입력입니다. 정수값을 입력해주세요.");
}
if( memoNumUp == -1 ) // 잘못 입력했으면 break로 빠져나감.
break;
if ( memoList.checkMemoExistOrNot(memoNumUp) ) { // 찾는 번호의 메모 존재 시
System.out.println("글의 비밀번호를 입력해주세요.");
String pw = s.nextLine();
if(pw.equals(memoList.getMemoPasswordByNum(memoNumUp))){
System.out.println("수정할 내용 작성 : ");
String newContent = s.nextLine();
memoList.updateMemo(memoNumUp, newContent);
} else { // 비밀번홀가 틀렸다면
System.out.println("비밀번호가 틀렸습니다.");
}
} else { // 찾는 번호의 메모 존재 x
System.out.println("찾으시는 번호에 해당하는 메모가 없습니다.");
}
break;
case 4: // 4. 메모 삭제
System.out.println("삭제할 글 번호를 입력해주세요.");
int memoNumDel = -1; // 초기값 설정. 글 번호에는
// memoNumDel => 삭제하고 싶은 글번호
try {
memoNumDel = Integer.parseInt(s.nextLine());
}catch(NumberFormatException e){ // 정수가 아닌 이상한 값을 입력할 때.
System.out.println("잘못된 입력입니다. 정수값을 입력해주세요.");
}
if( memoNumDel == -1 ) // 잘못 입력했으면 break로 빠져나감.
break;
if ( memoList.checkMemoExistOrNot(memoNumDel) ) { // 찾는 번호의 메모 존재 시
System.out.println("글의 비밀번호를 입력해주세요.");
String pw = s.nextLine();
if(pw.equals(memoList.getMemoPasswordByNum(memoNumDel))){
memoList.deleteMemo(memoNumDel);
} else { // 비밀번홀가 틀렸다면
System.out.println("비밀번호가 틀렸습니다.");
}
} else { // 찾는 번호의 메모 존재 x
System.out.println("찾으시는 번호에 해당하는 메모가 없습니다.");
}
break;
case 5:
System.out.println("정상적으로 종료되었습니다.");
System.exit(0);
break;
case -1: // 잘못 입력한 경우이기에 아무 일도 일어나지 않음.
;
}
}
}
void showMenu(){
System.out.println("=====================");
System.out.println("1. 메모 쓰기");
System.out.println("2. 메모 목록보기");
System.out.println("3. 메모 수정하기");
System.out.println("4. 메모 삭제하기");
System.out.println("5. 종료");
System.out.println("=====================");
System.out.println("입력 : ");
}
}