Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA e is a sequence of characters that is the same when read forwards and backwards. The following are all palindromes: o Anna o live

JAVAimage text in transcribedimage text in transcribed

e is a sequence of characters that is the same when read forwards and backwards. The following are all palindromes: o Anna o live devil Able was I, ere I saw Elba.1 e Notice that we consider only the letters-ignoring case, punctuation, and whitespace when we look for palindromes We can recursively test a String s to see if it is a palindrome using the foll algorithm o Calculate the length of the string If the s has length 0 or length 1, then s is a palindrome. This is the base case If the first and last letters of the s are the same, then form a substring of s consisting of the letters in position 1 to length - 2. If this substring is a palindrome, then s is a palindrome. This is the recursive definition Otherwise, s is not a palindrome o e In this project, we are going to write a program that reads lines from a text file and determines if each line is a palindrome You should create your program in two parts. In the first part, write a class called Strippedstring that stores a String and a "stripped" version of the String The stripped version contains only the alphabetic characters of the String, with cach alphabetic character converted to lowercase if necessary. Your class should have a constructor that takes a single String, stripped version. The Character wrapper class contains methods named isLetter () and toLowerCase() that you will find useful when you write strip(). See the Java API for information about these meth and a method called strip() that returns the Once you h ave written StrippedString, write a main class that prompts the user for the name of a text file. For each line of text in the file, create a StrippedString object, and then use the stripped version of the line to determine whether it is a palindrome. Your main class must have a function that takes a String as a parameter and uses the recursive algorithm to determine if it is a palindrome. Finally, print out the palindrome status of the line, followed by the original line of text from the file Suppose that the file "string_list.txt" contains the following lines

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions