package com.example.andrewhanks.myapplication.chainofresponsibility;

abstract class Handler {
    protected Handler next;

    Handler(Handler next) {
        this.next = next;
    }

    void doNext(char c) {
        if (next != null) {
            next.handle(c);
        }
    }

    abstract void handle(char c);
}

class SymbolHandler extends Handler {
    SymbolHandler(Handler next) {
        super(next);
    }

    void handle(char c) {
        System.out.println("Symbol has been handled");
        doNext(c);
    }
}

class CharacterHandler extends Handler {
    CharacterHandler(Handler next) {
        super(next);
    }

    void handle(char c) {
        if (Character.isLetter(c)) {
            System.out.println("Character has been handled");
        }
        doNext(c);
    }
}

class DigitHandler extends Handler {
    DigitHandler(Handler next) {
        super(next);
    }

    void handle(char c) {
        if (Character.isDigit(c)) {
            System.out.println("Digit has been handled");
        }
        doNext(c);
    }
}
@@ -755,33 +755,44 @@
 led%22);%0A        %7D
-%0A
+ else %7B%0A    
         doNext(c
@@ -786,32 +786,42 @@
      doNext(c);%0A
+        %7D%0A
     %7D%0A%7D%0A%0Aclass D
@@ -1036,25 +1036,36 @@
 );%0A        %7D
-%0A
+ else %7B%0A    
         doNe
@@ -1055,31 +1055,41 @@
 %0A            doNext(c);%0A
+        %7D%0A
     %7D%0A%7D

Modify codes to avoid redundant function call