Question: The starter project contains LittleRecursions.java. This file has 4 methods already stubbed out with full Javadoc. Your job is to correctly write these 4 methods
The starter project contains LittleRecursions.java. This file has 4 methods already stubbed out with full Javadoc. Your job is to correctly write these 4 methods without using loops. You may notice that no driver file has been provided. In order to write this code successfully, you need to be creating your own tests to verify expected input and output to the methods. Be sure to use JUnit4 when you create your unit test files, or you will encounter a compilation error in WebCAT. Any unit tests you write should have file names ending in Test or Tests. public class LittleRecursions { /** * Determines if a given String is a palindrome * (meaning it is the same forwards and backward). * Comparison of characters are not case sensitive. * *
Thus, the following are palindromes * RACECAR * rAcECar * aBbA *
The following are NOT palindromes * DOG * Taylor Swift * OO00 * * @param s The string to check for palindrome status. * @return True if and only if s is a palindrome; false otherwise. */ public static boolean isPalindrome(String s) { //TODO: Replace with your solution. return false; } /** * Creates a string like the one given in the input parameter, but * with all letters in reverse order. All non-letters will be * removed from the final string. For example: * *
reverseSome("asdf") ==> "fdsa" * reverseSome("this is a test") ==> "tsetasisiht" * reverseSome("ABC 123!") ==> "CBA" * * @param s The string to reverse. * @return A version of s in which all letter characters are in * the reverse order of the original. */ public static String reverseSome(String s) { //TODO: Replace with your solution. return ""; } /** * This method computes the greatest common divisor * of two numbers using Euclid's algorithm. * *
Mathematically, gcd is recursively defined as: * gcd(x, 0) = x * gcd(x, y) = gcd(y, x mod y) * * @param x The first operand in the greatest common divisor. * @param y The second operand in the greatest common divisor. * @return The greatest common divisor of x and y. */ public static int gcd(int x, int y) { //TODO: Replace with your solution. return 0; } /** * Computes the sum of all positive values in the * array parameter. * * @param array The array of values to consider * @return The additive sum of all integers in array that are * positive. The sum will be 0 when the array * parameter is null. */ public static int sumPositive(int[] array) { //HINT: A helper method might be useful here... //TODO: Replace with your solution. return 0; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
