Java Problems
The Java problems consist of a single Java class (ProblemX.java). The concrete set of inputs is specified at the top of the class definition as a set of plain character sequences (Strings) or their corresponding integer value for the integer version.
private String[] inputs = {"D","E","A","F","B","C"};
The central method is calculateOutput, which comprises the program's logic. It is realized in terms of a sequence of nested if-then-else blocks. The state of a system is maintained in a set of attributes.
public String calculateOutput(String input) { if (cf && input.equals(inputs[2]) // EVENT && (b0==true && i0==9 && s0.equals("e"))) // CONDITION { s0 = "g"; // ACTION b1 = true; System.out.println("Z"); } else if ... { ... } ... errorCheck(); if(cf) throw new IllegalArgumentException("Current state has no transition for this input!"); }
At the bottom of this method, there is a method errorCheck which contains a sequence of if-statements, checking whether the system is in an invalid state. If this is the case, an IllegalStateException with the respective error code is thrown.
private void errorCheck() { ... if(a23 && a3 && a6 && a26 == 3 && a15 && a18.equals("e")) throw new IllegalStateException( "error_23" ); ... }
Problems come with a main method, instantiating the problem and exposing it to continuous inputs on stdin which occasionally produces output on stdout.
public static void main(String[] args) throws IOException { // init system Problem eca = new Problem(); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); // main i/o-loop while(true) { // read input String input = stdin.readLine(); try{ //operate eca engine output = eca.calculateOutput(input); } catch(IllegalArgumentException e){ System.err.println("Invalid input: " + e.getMessage()); } } }
The systems can be compiled using javac and executed using java without any prerequisites.
$ javac ProblemX.java $ java ProblemX A X . . .