Question: Create a new Java project called 1410_Recursion. Add a package recursion and a class Recursion. Include the following three static methods described below. However, don't
Create a new Java project called 1410_Recursion. Add a package recursion and a class Recursion. Include the following three static methods described below. However, don't implement them right away. Instead, start by returning the default value followed by a // TODO comment.
- public static int sumOfDigits(int n) This method returns the sum of all the digits. sumOfDigits(-34) -> 7 sumOfDigits(1038) -> 12
- public static int countSmiles(char[] letters, int index) This method counts the number of colons followed by a closing parenthesis. countSmiles([:,), ,L,i,f,e, ,i,s, ,g,o,o,d, ,:,)], 0) -> 2 countSmiles([H,a,p,p,y, ,D,a,y, ,:,),:,),:,),!], 0) -> 3 countSmiles([a,:,b,(,c,),:, ,),e], 0) -> 0
- public static String toUpper(String str) This method separates all characters by a space and changes all lowercase letters to uppercase letters. E.g. "Hi there!" returns "H I T H E R E !" Hint: Class Character (Links to an external site.) includes a method toUpperCase (Links to an external site.)
Create a second source folder called test. It should include a class RecursionTest. That's where you will write the JUnit tests for the three methods above.
- Each of the three methods should have at least eight corresponding JUnit tests.
- Choose test data deliberately to provide thorough testing that covers as many potential problems as possible.
Once you have written the JUnit tests, implement the methods.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
