@@ -0,0 +1,1935 @@
+import java.util.ArrayList;%0Aimport java.util.Random;%0A%0Apublic class Belt %7B%0A    %0A    public  String%5B%5D belt;%0A    private int%5B%5D    beltState; // state of the belt --%3E three states: empty, with component, with product%0A    private int      L;%0A    private int      nC;%0A    %0A    ArrayList beltOutput = new ArrayList();%0A    %0A    public Belt(int L, int nC)%7B%0A        %0A        this.L    = L;%0A        this.nC   = nC;%0A        belt      = new String%5BL%5D;%0A        %0A        for(int i=0; i%3CL; i++)%7B%0A            belt%5Bi%5D = null; // initial belt is empty%0A        %7D%0A        %0A        beltState = new int%5BL%5D;%0A        %0A        init();%0A        %0A    %7D%0A    %0A    private void init()%7B%0A        %0A        // add new component to the belt%0A        Random randomGenerator = new Random();%0A        int value = randomGenerator.nextInt(nC+1);%0A        if (value%3E0)%7B%0A            value = value + 64; // ASCII Set: A=65, B=66, etc%0A            belt%5B0%5D = Character.toString((char)value);%0A        %7D else %7B%0A            belt%5B0%5D = null;%0A        %7D%0A        updateBeltState();%0A        %0A    %7D%0A    %0A    private void updateBeltState()%7B%0A        %0A        for(int i=0; i%3CL; i++)%7B%0A            if(belt%5Bi%5D==null)%7B%0A                beltState%5Bi%5D = 3;     // belt empty%0A            %7D else if(%22P%22.equals(belt%5Bi%5D))%7B%0A                beltState%5Bi%5D = 2;     // belt with product%0A            %7D else beltState%5Bi%5D = 1;  // belt with component%0A        %7D%0A        %0A    %7D%0A    %0A    public void updateBelt(String%5B%5D B)%7B%0A        System.arraycopy(B, 0, belt, 0, L);  %0A        updateBeltState();%0A    %7D%0A    %0A    public void slideBelt()%7B%0A        %0A        String%5B%5D beltTemp = new String%5BL%5D;%0A        %0A        if(belt%5BL-1%5D!=null)%7B%0A            beltOutput.add(belt%5BL-1%5D);%0A        %7D        %0A        for(int i=1; i%3CL; i++)%7B%0A            beltTemp%5Bi%5D = belt%5Bi-1%5D;%0A        %7D%0A        System.arraycopy(beltTemp, 0, belt, 0, L);%0A        init();%0A        %0A    %7D%0A    %0A    public int%5B%5D getBeltState()%7B%0A        return beltState;%0A    %7D%0A    %0A%7D%0A

Create Belt.java