Answered step by step
Verified Expert Solution
Question
1 Approved Answer
6. Consider the following Java method. /** (Total: 77 = 14 marks) * Returns a palindrome version of a String where the * original
6. Consider the following Java method. /** (Total: 77 = 14 marks) * Returns a palindrome version of a String where the * original String is followed by its reverse. * * @param s a String that we want to make into a palindrome * @returns followed by the reverse of s * @throws IllegalArgumentException if s is null */ public static String toPalindrome (String s) { if (s == null) throw new IllegalArgumentException(); String result = ""; for (int i = 1; i >= 0; i--) { results.charAt(i) + result%;B s.length() result results.charAt(i); } return result; } (a) Write test cases for JUnit 4 that together achieve test coverage for this method (i.e., for each statement in the method to Palindrome there should be at least one test case that uses the statement). Ensure that a test fails if running the test takes more than 3000 milliseconds. Hint: Remember to use suitable Java annotations to label methods as JUnit test cases. 7 mark (b) Write a recursive method 7 mark public static String toPalindrome Recursive(String s) that has the same functionality as the method to Palindrome. You are not allowed to use loops for this method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
a Here are some test cases for JUnit 4 that achieve test coverage for the toPalindrome method import ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started