@@ -0,0 +1,2268 @@
+import java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Scanner;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Apublic class StringCalculator %7B%0A%0A    private static final int MAX = 1000;%0A    private static final String CUSTOM_DELIMITER = %22//%22;%0A    private static final String DEFAULT_DELIMITERS = %22,%7C%5Cn%22;%0A%0A    public int add(String expression) %7B%0A        if (expression.isEmpty()) %7B%0A            return 0;%0A        %7D%0A%0A        String delimiters = DEFAULT_DELIMITERS;%0A%0A        Scanner scanner = new Scanner(expression);%0A%0A        if (expression.startsWith(CUSTOM_DELIMITER)) %7B%0A            String firstLine = scanner.nextLine();%0A            List%3CString%3E delimiterList = new ArrayList%3CString%3E();%0A            Pattern pattern = Pattern.compile(%22%5C%5C%5B(.*?)%5C%5C%5D%22);%0A            Matcher matcher = pattern.matcher(firstLine);%0A            while (matcher.find()) %7B%0A                delimiterList.add(matcher.group(1));%0A            %7D%0A            if (delimiterList.isEmpty()) %7B%0A                delimiters = firstLine.replace(CUSTOM_DELIMITER, %22%22).replaceAll(%22%5C%5C%5D%7C%5C%5C%5B%22, %22%22);%0A                delimiters = Pattern.quote(delimiters);%0A            %7D else %7B%0A                StringBuilder builder = new StringBuilder();%0A                for (int i = 0; i %3C delimiterList.size() - 1; i++) %7B%0A                    builder.append(Pattern.quote(delimiterList.get(i))).append(%22%7C%22);%0A                %7D%0A                builder.append(Pattern.quote(delimiterList.get(delimiterList.size() - 1)));%0A                delimiters = builder.toString();%0A            %7D%0A        %7D%0A%0A        scanner.useDelimiter(%22%5C%5Cz%22);%0A        return performSum(scanner.next(), delimiters);%0A    %7D%0A%0A    private int performSum(String expression, String delimiters) %7B%0A        int sum = 0;%0A        StringBuilder negatives = new StringBuilder();%0A        for (String term : expression.split(delimiters)) %7B%0A            int number = Integer.parseInt(term);%0A            if (number %3C 0) %7B%0A                negatives.append(number).append(%22 %22);%0A            %7D else if (number %3C= MAX) %7B%0A                sum += number;%0A            %7D%0A        %7D%0A        if (!negatives.toString().isEmpty()) %7B%0A            throw new IllegalArgumentException(%22Negatives not allowed: %22 + negatives.toString());%0A        %7D%0A        return sum;%0A    %7D%0A%7D%0A

Create StringCalculator.java