Skip to content

Commit 1811f15

Browse files
committed
feat: 입출력 구현체 구현
1 parent 87aa862 commit 1811f15

6 files changed

Lines changed: 47 additions & 8 deletions

File tree

calculator/doc/기능_목록.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 입력
66

7-
- [ ] 메뉴 번호를 입력받는다.
7+
- [x] 메뉴 번호를 입력받는다.
88
- [ ] 계산 시, 중위 연산식을 입력받는다.
99

1010
### 출력

calculator/src/main/java/com/wonu606/Main.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
import com.wonu606.app.App;
44
import com.wonu606.calculator.CalculatorApp;
5+
import com.wonu606.io.ConsolePrinter;
56
import com.wonu606.io.Input;
67
import com.wonu606.io.Print;
8+
import com.wonu606.io.ConsoleInput;
79
import java.io.IOException;
810

911
public class Main {
1012

1113
public static void main(String[] args) {
12-
Input input;
13-
Print printer;
14+
Input input = new ConsoleInput();
15+
Print printer = new ConsolePrinter();
1416

1517
CalculatorApp app = new CalculatorApp();
1618
try {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.wonu606.io;
2+
3+
import java.io.IOException;
4+
import java.util.Scanner;
5+
6+
public class ConsoleInput implements Input {
7+
8+
Scanner scanner = new Scanner(System.in);
9+
10+
@Override
11+
public String getInput() throws IOException {
12+
return scanner.nextLine();
13+
}
14+
15+
@Override
16+
public void tearDown() {
17+
scanner.close();
18+
}
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.wonu606.io;
2+
3+
public class ConsolePrinter implements Print {
4+
5+
@Override
6+
public void print(String message) {
7+
System.out.println(message);
8+
}
9+
10+
@Override
11+
public void print(int number) {
12+
print(String.valueOf(number));
13+
}
14+
15+
@Override
16+
public void tearDown() {
17+
}
18+
}

calculator/src/test/java/com/wonu606/io/ConsoleInputTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void testMenuSelectionInput() throws IOException {
1717
InputStream in = new ByteArrayInputStream(menuSelection.getBytes());
1818
System.setIn(in);
1919

20-
Input input;
20+
Input input = new ConsoleInput();
2121
assertThat(menuSelection).isEqualTo(input.getInput());
2222
input.tearDown();
2323
}
@@ -29,7 +29,7 @@ void testExpressionInput() throws IOException {
2929
InputStream in = new ByteArrayInputStream(expression.getBytes());
3030
System.setIn(in);
3131

32-
Input input;
32+
Input input = new ConsoleInput();
3333
assertThat(expression).isEqualTo(input.getInput());
3434
input.tearDown();
3535
}
@@ -41,7 +41,7 @@ void testNewLineInput() throws IOException {
4141
InputStream in = new ByteArrayInputStream(newLine.getBytes());
4242
System.setIn(in);
4343

44-
Input input;
44+
Input input = new ConsoleInput();
4545
assertThat("").isEqualTo(input.getInput());
4646
input.tearDown();
4747
}

calculator/src/test/java/com/wonu606/io/ConsolePrinterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void testIntegerPrint() {
1616
OutputStream out = new ByteArrayOutputStream();
1717
System.setOut(new PrintStream(out));
1818

19-
Print printer;
19+
Print printer = new ConsolePrinter();
2020
int number = -1;
2121
printer.print(number);
2222

@@ -29,7 +29,7 @@ void testStringPrint() {
2929
OutputStream out = new ByteArrayOutputStream();
3030
System.setOut(new PrintStream(out));
3131

32-
Print printer;
32+
Print printer = new ConsolePrinter();
3333
String str = "Hello World";
3434
printer.print(str);
3535

0 commit comments

Comments
 (0)