Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Create class that performs different functions on Strings that are sent to it.
All the methods you create will be static. Only two methods (mentioned below) and the main
method need to be public. Any other methods that you write to help these methods should be
private because they are only used internally within the class.

Requirements:
1. Prompt users to enter 3 string inputs. Consider strings with alphabetic characters (a - z, A - Z)
and/or numbers (0 - 9) as valid. Strings contain only non-word characters are invalid. Print the following usage when an input string is invalid or is
empty.
Usage: Enter a string that contains alphabetic characters and numbers

2. Create a method "isPalindrome" that takes a String as a parameter and returns true if the
given String parameter is a palindrome and false if it is not. In your main method, this method
should be call with the first user input and print either "The given string is a palindrome." or
"The given string is not a palindrome." as output based on the returned value.

A word is a palindrome if it reads the same forwards and backwards. For example, the
word "level" is a palindrome. The idea of a palindrome can be extended to phrases or
sentences if we ignore details like punctuation. Here are two familiar examples:
Madam, I'm Adam
A man, a plan, a canal: Panama
We can recognize these more elaborate examples as palindromes by considering the text
that is obtained by removing all spaces and punctuation marks and converting all letters
to their lower-case form.

Madam, I'm Adam ==> madamimadam
A man, a plan, a canal: Panama ==> amanaplanacanalpanama
If the "word" obtained from a phrase in this manner is a palindrome, then the phrase is a
palindrome. Your method should also ignore the case of the letters. A palindrome is
determined by considering only alphabetic characters (a - z, A - Z) and numbers (0 - 9)
as valid text.

3. Create another method named "findSubstring" that takes 3 strings as parameters and checks if
the first string contains a substring that starts with the second string, ends with the third string,
and has an even number of characters in between†. Return the substring if it exists and return
null if not. This method will be called in your main method with all three user inputs and print
either "The substring is <substring>" or "No such substring in the given string."‡ as output
based on the returned value. Your method should ignore the letter case and assume that no more
than one such substring exists in the initial string.

4. Your output should be like the following test samples.

Sample Test Cases:
Test Case 1:
Please enter a string:
ATGCGATAC6TA
Please enter a string:
atg
Please enter a string:
6ta

The given string is "ATGCGATAC6TA" Notes:Count only alphabetic characters and numbers.

Replace <substring> with corresponding values.
The prefix is "atg"
The suffix is "6ta"

The given string is not a palindrome.

The substring is "ATGCGATAC6TA"

Program Completed

Test Case 2:
Please enter a string:
*^_^*
Usage: Enter a string that contains alphabetic characters and numbers
Please enter a string:
Was it a car or a cat i saw?
Please enter a string:
car
Please enter a string:
cow

The given string is "Was it a car or a cat i saw?"
The prefix is "car"
The suffix is "cow"

The given string is a palindrome.
No such substring in the given string.

Program Completed

Test Case 3:
Please enter a string:
Lewd did I live, & evil I did dwel.
Please enter a string:
did
Please enter a string:
did

The given string is "Lewd did I live, & evil I did dwel."
The prefix is "did"
The suffix is "did"

The given string is a palindrome.

The substring is "did I live, & evil I did"

Program Completed

Notes:
The program should always print 'Program Completed' before exiting.

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education