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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 11:00, loveworld3798
When working with a team you should always do the following, except? question 3 options: be dependable and trustworthy be sensitive to others feelings do your fair share critique members of the group
Answers: 2
image
Computers and Technology, 22.06.2019 15:30, micahpauleen748
In a compound condition, both conditions on either side of the logical operator and must be true for the overall condition to be true. a: true b: false
Answers: 1
image
Computers and Technology, 22.06.2019 19:30, mitalichavez1
When creating a presentation in libre office impress, where does the editing of slides take place? a. the slides panel b. the center panel c. the tasks panel, under the masters pages tab d. the tasks panel, under the layouts tab
Answers: 3
image
Computers and Technology, 23.06.2019 13:00, dimondqueen511
Which one of the following voltages should never be measured directly with a vom? a. 1200 v b. 500 v c. 800 v d. 100v
Answers: 2
You know the right answer?
Test palindrome

a string like "radar", "racecar", and "abba"that reads the same in eith...

Questions in other subjects: