subject

SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. 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 palindromeChecker(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;

}

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 CallPrinted Message
palindromeChecker("taco cat")taco cat is a palindrome
palindromeChecker("laid on no dial")laid on no dial is a palindrome
palindromeChecker("level up")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)

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 16:30
Which type of computing device is best suited to having a digital pen as an input device? a. personal computer b. personal digital assistant c. smart television d. laptop e. mobile phone
Answers: 3
question
Computers and Technology, 23.06.2019 06:30
Which option correctly describes a dbms application? a. software used to manage databases b. software used to organize files and folders c. software used to develop specialized images d. software used to create effective presentations
Answers: 1
question
Computers and Technology, 23.06.2019 08:00
What is a scenario where records stored in a computer frequently need to be checked
Answers: 2
question
Computers and Technology, 23.06.2019 23:30
Perform an online search about the booting process of a computer and list all the steps
Answers: 2
You know the right answer?
SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the class...
Questions
question
Arts, 12.02.2021 05:40
question
Mathematics, 12.02.2021 05:40
question
Mathematics, 12.02.2021 05:40
question
Mathematics, 12.02.2021 05:40
Questions on the website: 13722361