6. Consider the following Java method. /** (Total: 77 = 14 marks) * Returns a palindrome...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Answer rating: 100% (QA)
a Here are some test cases for JUnit 4 that achieve test coverage for the toPalindrome method import ... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Microkernel operating systems aim to address perceived modularity and reliability issues in traditional "monolithic" operating systems. (i) Describe the typical architecture of a microkernel...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Calculate the density of N2 at STP, (a) using the ideal-gas law and (b) using the molar volume and molar mass of N2. How do the densities compare?
-
The industrial synthesis of methyl tert-butyl ether involves treatment of 2-methylpropene with methanol (CH3OH) in the presence of an acid catalyst, as shown in the following equation. CH3 H3C H3C...
-
Calculate the limit for the given function and interval. Verify your answer by using geometry. lim MN, f(x) = 12 - 4x, [2, 6] N00
-
In 2019, Italia Mining Corporation had sales of \($69\) million, total assets of \($45\) million, and total liabilities of \($23\) million. The interest rate on the debt is 6.5 percent, and its tax...
-
Jerry Smith is thinking about opening a bicycle shop in his hometown. Jerry loves to take his own bike on 50-mile trips with his friends, but he believes that any small business should be started...
-
You are planning a 30-day vacation in Malaysia in one year's time. The present charge for a luxury suite plus meals is RM760.00 per day and the RM is presently trading at RM 3.8000/$. Hence the $...
-
Consider the following TIPS bond purchased one year ago. The bond had an original principal value of $1,000 and pays a 10% annual coupon payment that is paid semiannual. Inflation for the first 6...
-
Your pro forma income statement shows sales of $1,022,000, cost of goods sold as $483,000, depreciation expense of $97,000, and taxes of $176,800 due to a tax rate of 40%. What are your pro forma...
-
What is meant by bias in an estimator? What is meant by consistency of an estimator? What is the difference between an estimate and an estimator? Give examples.
-
How does autocorrelation impact the standard error of the coefficient estimate?
-
You are evaluating a new product. In year 3 of your analysis, you are projecting pro forma sales of $5.8 million and cost of goods sold of $3.48 million. You will be depreciating a $1 million machine...
-
An ICU has 20 beds. The average length of time a patient stays in the ICU once placed there is 5 days. The standard deviation of this time is 7 days. Patients arrive to the ICU at a rate of 3.7 per...
-
Watch the film 'Invictus' (2009), describing the role of the leader in the process of a culture shift. Identify the factors that Nelson Mandela used to create and sustain a "positive culture",...
-
Pearl Medavoy will invest $10,240 a year for 20 years in a fund that will earn 10% annual interest. . If the first payment into the fund occurs today, what amount will be in the fund in 20 years? If...
-
If you look at the light spectrum reflected from the surface of a DVD compared to the spectrum reflected from the surface of a CD, youll see that the rainbows from the DVD are more spread out, with...
-
DVDs and Blu-ray disks store information in patterns that are read by laser light. The shorter the wavelength of the light, the closer the data tracks can be placed on the disk. A Blu-ray player uses...
-
Increasing the density of a material tends to increase the index of refraction. Does light travel faster in seawater or in fresh water?
Study smarter with the SolutionInn App