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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 00:10, makailaaa2
My has been slow anyone else’s ?
Answers: 1
image
Computers and Technology, 23.06.2019 18:30, erjalinalii
Janice recently received her college degree and is looking for a job. she is worried that since she just finished school, she will be required to repay her perkins and direct subsidized loans immediately. janice pulls out the paperwork she signed and reviews it again for repayment information. after reading all of the information, janice discovers that
Answers: 2
image
Computers and Technology, 23.06.2019 20:00, boo3972
Match the file formats with the types of multimedia they can store
Answers: 2
image
Computers and Technology, 25.06.2019 03:40, NBASTARK4523
Acurrent vehicle registration expires at of the first owner listed on the registration form. a. stretch and flex b. bend and break c. wear down d. bounce around
Answers: 1
You know the right answer?
SHOW ALL YOUR WORK. REMEMBER THAT PROGRAM SEGMENTS ARE TO BE WRITTEN IN JAVA. Assume that the class...

Questions in other subjects:

Konu
Physics, 06.05.2021 14:00
Konu
Mathematics, 06.05.2021 14:00