-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathCalcConsoleView.java
More file actions
61 lines (46 loc) · 1.5 KB
/
CalcConsoleView.java
File metadata and controls
61 lines (46 loc) · 1.5 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
package calcproject.view.console;
import java.util.List;
import java.util.Scanner;
import calcproject.models.CalcResultRecordModel;
import calcproject.view.CalcInput;
import calcproject.view.CalcOutput;
import calcproject.view.Command;
import calcproject.view.Messages;
public class CalcConsoleView implements CalcInput, CalcOutput {
private Scanner scanner;
public CalcConsoleView() {
this.scanner = new Scanner(System.in);
}
@Override
public Command getCmd() {
System.out.println(Messages.INPUT_GUIDE_MESSAGE.getMessage());
System.out.print(Messages.INPUT_CHOICE_MESSAGE.getMessage());
int choiceNum = this.scanner.nextInt();
this.scanner.nextLine();
return Command.valueOf(choiceNum);
}
@Override
public String getExpression() {
String expression = this.scanner.nextLine();
return expression;
}
@Override
public void showCalcResult(CalcResultRecordModel calcResultRecordModel) {
System.out.println(calcResultRecordModel.getCalcResult() + "\n");
}
@Override
public void showRecord(List<CalcResultRecordModel> calcResultRecordModelList) {
calcResultRecordModelList.
forEach(calcRecord -> calcRecordToFormattedStr(calcRecord));
System.out.println();
}
private String calcRecordToFormattedStr(CalcResultRecordModel calcRecord) {
String expression = calcRecord.getExpression();
double calcResult = calcRecord.getCalcResult();
return expression + " = " + calcResult;
}
@Override
public void showExitMessage() {
System.out.println(Messages.EXIT_MESSAGE.getMessage());
}
}