-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathConsole.java
More file actions
48 lines (40 loc) · 1.22 KB
/
Console.java
File metadata and controls
48 lines (40 loc) · 1.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
package com.programmers;
import com.programmers.engine.io.Input;
import com.programmers.engine.io.Output;
import java.util.Map;
import java.util.Scanner;
public class Console implements Input, Output {
private final Scanner sc = new Scanner(System.in);
@Override
public void showMenu() {
System.out.println("1. 조회\n2. 계산\n3. 종료\n");
}
@Override
public void inputError() {
System.out.println("잘못된 입력입니다. 다시 선택해주세요!");
}
@Override
public int selectMenu() {
System.out.print("선택 : ");
return Integer.parseInt(sc.nextLine());
}
@Override
public String getExpression() {
System.out.println("계산하고자 하는 식을 입력해주세요!");
return sc.nextLine();
}
@Override
public void readAllResults(Map<Integer, String> map) {
if (map.isEmpty()) {
System.out.println("계산 이력이 없습니다.");
return;
}
System.out.println();
map.forEach((key, value) -> System.out.println(value));
System.out.println();
}
@Override
public void printAnswer(int answer) {
System.out.println(answer);
}
}