subject

Test palindrome

a string like "radar", "racecar", and "abba"that reads the same in either direction. to enable longer palindromes, we can ignore spaces, punctuation, and the cases of the letters. for example:

"a man, a plan, a canal, panama! "
is a palindrome, because if we ignore spaces and punctuation and convert everything to lowercase we get

"amanaplanacanalpanama"
which is a palindrome.

in the file palindrome. java add a static method called ispal() that takes a string object as a parameter and determines if it is a palindrome, returning true if it is and false if it is not.

a string of length 1 and an empty string should both be considered palindromes. throw an exception for null values.

although we can implement solutions to this problem using recursion or an appropriately constructed loop that manipulates the string object directly, your method must use an instance of one of the following collection classes from arrayqueue

you must not use any other data structure, including arrays or linked lists other than the ones that are "inside" instances of the above collections. rather, you should put individual characters from the original string into an instance of one or more of the above collections, and use those collection object(s) to determine if the string is a palindrome.

for full credit, you should:

write your method so that spaces, punctuation, and the cases of the letters don’t prevent a string from being a palindrome. to put it another way, make sure that your method only considers characters in the string that are letters of the alphabet and that it ignores the cases of the letters. see our example above.

make your method as efficient as possible. in particular:

you should perform only one iteration over the original string object. after that one iteration, any additional manipulations of the characters should be done using the collection object(s) that you have chosen to use.

because we want to avoid unnecessary scanning, you may not use any of the built-in string methods except charat() and

hints:

when constructing the collection object(s) that you decide to use, you will need to specify the appropriate data type for the items in the collection. because char values are primitives, you should use the corresponding "wrapper" class, which is called character.

you may also find it to use the character. tolowercase() or character. touppercase() method.

remember that char values are essentially integers, so you can compare them just as you would compare integers.

(5 points) for professional programmers, writing well-formatted units tests is an extremely important part of their work. in the main() method of palindrome. java, we’ve given you an example of what such a unit test should look like.

add five additional unit tests for your ispal() method to the main() method. your unit tests must follow the same format as our example test. in particular, the output of each of your unit tests should include:

a header that specifies the test number and a description of what is being tested
the actual return value that you get from that test
the expected return value
whether the actual return value matches the expected return value.
put each test in the context of a try-catch block so that you can handle any exceptions that are thrown. leave a blank line between tests.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 06:50
Match the personality traits with their description
Answers: 1
question
Computers and Technology, 22.06.2019 11:30
Awell-diversified portfolio needs about 20-25 stocks from different categories.
Answers: 2
question
Computers and Technology, 22.06.2019 13:50
The instruction ishl (shift left integer) exists in jvm but not in ijvm. it uses the top two values on the stack, replacing the two with a single value, the result. the sec- ond-from-top word of the stack is the operand to be shifted. its content is shifted left by a value between 0 and 31, inclusive, depending on the value of the 5 least signifi- cant bits of the top word on the stack (the other 27 bits of the top word are ignored). zeros are shifted in from the right for as many bits as the shift count. the opcode for ishl is 120 (0x78).a. what is the arithmetic operation equivalent to shifting left with a count of 2? b. extend the microcode to include this instruction as a part of ijv.
Answers: 1
question
Computers and Technology, 22.06.2019 18:30
Which of these options are the correct sequence of actions for content to be copied and pasted? select content, click the copy button, click the paste button, and move the insertion point to where the content needs to be inserted. click the copy button, select the content, move the insertion point to where the content needs to be inserted, and click the paste button. select the content, click the copy button, move the insertion point to where the content needs to be inserted, and click the paste button. select the content, move the insertion point to where the content needs to be inserted, click the copy button, and click the paste button.
Answers: 3
You know the right answer?
Test palindrome

a string like "radar", "racecar", and "abba"that reads the same in eith...
Questions
question
Mathematics, 27.03.2020 16:20
Questions on the website: 13722363