Java Problems

The information below is specific to the Java problems. General instructions / explanations can be found here.

The Java implementations of the ECA systems consist of a single Java class. The concrete set of inputs is specified at the top of the class definition as a set of plain character sequences (Strings).

    private String[] inputs = {"D","E","A","F","B","C"};

The central method is calculateOutput, which comprises the ECA logic. It is realized in terms of a sequence of nested if-then-else blocks. The state of an ECA system is maintained in a set of attributes.

    public String calculateOutput(String input)    
    {
        if (input.equals(inputs[2])             	// EVENT
            && (b0==true && i0==9 && s0.equals("e")))   // CONDITION 
        {
            s0 = "g";                           	// ACTION
            b1 = true;
            return "X";
        } 
        else if ... {
           ...
        }
        ...
        throw new IllegalArgumentException(" Invalid input "); 
    }

At the bottom of this method, there is 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.

	public String calculateOutput(String input) {
		...
		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 inputs on stdin and producing output on stdout

    public static void main(String[] args) throws IOException 
    {
        // default output
        String output = "NotInitialized";

        // init eca-system and input reader
        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);
                if(output != null)
                    System.out.println(output);
            }
            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                                   
    .
    .
    .