/Incubyte_Assignment

Primary LanguageJavaApache License 2.0Apache-2.0

Incubyte_Assignment

Main.java click
StringCalculator.java click

1 : Empty string as argument

public class Main {

    public static void main(String[] args) {
        //Instantiating the StringCalculator class
        StringCalculator sc = new StringCalculator();
        //Calling add method by passing string as argument
        System.out.println(sc.add("");
     }
  }
        

Output

0

2 : Single String Digit as argument

public class Main {

    public static void main(String[] args) {
        //Instantiating the StringCalculator class
        StringCalculator sc = new StringCalculator();
        //Calling add method by passing string as argument
        System.out.println(sc.add("1"));
    }
}

Output

1

3 : Multiple String Digit as argument

public class Main {

    public static void main(String[] args) {
        //Instantiating the StringCalculator class
        StringCalculator sc = new StringCalculator();
        //Calling add method by passing string as argument
        System.out.println(sc.add("1,2,3,4"));
    }
}

Output

10

4 : Allowing alphabets as argument and adding their standard position from alphabet table in sum

public class Main {

    public static void main(String[] args) {
        //Instantiating the StringCalculator class
        StringCalculator sc = new StringCalculator();
        //Calling add method by passing string as argument
        System.out.println(sc.add("a,b,c,d"));
    }
}

Output

10

5 : Combination of alphabets and numbers

public class Main {

    public static void main(String[] args) {
        //Instantiating the StringCalculator class
        StringCalculator sc = new StringCalculator();
        //Calling add method by passing string as argument
        System.out.println(sc.add("1,2,3,4,a,b,c,d"));
    }
}

Output

20

6 : Using ',' and '\n' as delimiter between alphabets and numbers

public class Main {

    public static void main(String[] args) {
        //Instantiating the StringCalculator class
        StringCalculator sc = new StringCalculator();
        //Calling add method by passing string as argument
        System.out.println(sc.add("1,2,3\n4,5,6\nA\nb"));
    }
}

Output

24

7 : Using custom delimiter taken as input from user which starts with "//"

public class Main {

    public static void main(String[] args) {
        //Instantiating the StringCalculator class
        StringCalculator sc = new StringCalculator();
        //Calling add method by passing string as argument
        System.out.println(sc.add("//:\n1:2:3:4:5:a:b"));
    }
}

Output

18

8 : Ignoring number greater than 1000

public class Main {

    public static void main(String[] args) {
        //Instantiating the StringCalculator class
        StringCalculator sc = new StringCalculator();
        //Calling add method by passing string as argument
        System.out.println(sc.add("1,2,3,1001,1000,1,2");
    }
}

Output

1009