Question
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit.
This question involves the StringManip class, which is used to perform manipulation on strings. The class provides the removeSpaces method, whose implementation is not shown. The method takes a string and returns a new string with spaces removed. For example, removeSpaces("hi how are you") returns "hihowareyou". The removeSpaces method will be used in part (b).
(a) Write method reverseString, which takes a string str and returns a new string with the characters in str in reverse order. For example, reverseString("ABCDE") should return "EDCBA". Complete the reverseString method below by assigning the reversed string to result.
(b) Write method palindromeChecker below. Assume that reverseString works as specified, regardless of what you wrote in part (a). You must use reverseString and removeSpaces appropriately to receive full credit. Your implementation must conform to the examples in the table.
Assume that the classes listed in the Java Quick Reference have been imported where appropriate. Unless otherwise noted in the question, assume that parameters in method calls are not null and that methods are called only when their preconditions are satisfied. In writing solutions for each question, you may use any of the accessible methods that are listed in classes defined in that question. Writing significant amounts of code that can be replaced by a call to one of these methods will not receive full credit. This question involves the stringManip class, which is used to perform manipulation on strings. The class provides the removeSpaces method, whose implementation is not shown. The method takes a string and returns a new string with spaces removed. For example, removeSpaces ("hi how are you") returns "hihowareyou". The removeSpaces method will be used in part (b). public class StringManip { /** Takes a string str and returns a new string with all spaces removed. */ public static String removeSpaces (String str) { /* implementation not shown */ } + /** Takes a string str and returns a new string * with the characters reversed, as described in part (a). */ public static String reverseString (String str) { /* to be implemented in part (a) */ } + /** Determines whether str is a palindrome and prints a message indicating the result, as described in part (b). * Precondition: str contains only lowercase letters and spaces. */ public static void palindrome Checker (String str) { /* to be implemented in part (b) */ } } (a) Write method reverseString, which takes a string str and returns a new string with the characters in str in reverse order. For example, reverseString("ABCDE") should return "EDCBA". Complete the reverseString method below by assigning the reversed string to result. /** Takes a string str and returns a new string * with the characters reversed. */ public static String reverseString (String str) { String result = ""; return result; } Please respond on separate paper, following directions from your teacher. For this question, let a palindrome be defined as a string that, when spaces are removed, reads the same forward and backward. For example, "race car" and "taco cat" are palindromes. You will write method palindromeChecker, which determines whether a string is a palindrome and prints a message indicating the result. Examples of the intended behavior of the method are shown in the following table. Method Call palindrome Checker ("taco cat") palindrome Checker ("laid on no dial") palindrome Checker("level up") Printed Message taco cat is a palindrome laid on no dial is a palindrome level up is not a palindrome (b) Write method palindromeChecker below. Assume that reverseString works as specified, regardless of what you wrote in part (a). You must use reverseString and removeSpaces appropriately to receive full credit. Your implementation must conform to the examples in the table. /** Determines whether str is a palindrome and prints a message * indicating the result, as described in part (b). * Precondition: str contains only lowercase letters and spaces. */ public static void palindromeChecker (String str) Please respond on separate paper, following directions from your teacher
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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