File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55### 입력
66
7- - [ ] 메뉴 번호를 입력받는다.
7+ - [x ] 메뉴 번호를 입력받는다.
88- [ ] 계산 시, 중위 연산식을 입력받는다.
99
1010### 출력
Original file line number Diff line number Diff line change 22
33import com .wonu606 .app .App ;
44import com .wonu606 .calculator .CalculatorApp ;
5+ import com .wonu606 .io .ConsolePrinter ;
56import com .wonu606 .io .Input ;
67import com .wonu606 .io .Print ;
8+ import com .wonu606 .io .ConsoleInput ;
79import java .io .IOException ;
810
911public 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 {
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments