/
Main.java
33 lines (29 loc) · 1.09 KB
/
Main.java
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
package net.m14m.romannumeralkata;
import java.io.*;
public class Main {
private final BufferedReader input;
private final PrintWriter output;
private final ExpressionParser expressionParser;
public Main(Reader input, Writer output) {
this.input = new BufferedReader(input);
this.output = new PrintWriter(output);
expressionParser = new ExpressionParser(
new RomanNumeralParser(),
new RomanNumeralFormatter(),
new ArabicNumeralParser(),
new ArabicNumeralFormatter()
);
}
public void execute() throws IOException {
String input;
while ((input = this.input.readLine()) != null) {
try {
Expression expression = expressionParser.parse(input);
String displayValue = expression.getFormatter().format(expression.getValue());
output.println(displayValue);
} catch (IllegalExpressionError illegalExpressionError) {
throw new RuntimeException(illegalExpressionError);
}
}
}
}