Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WordPalindrome.java Rules Below 1. Read a line from the console and convert it to lower-case and then remove any character which not a digit, not

WordPalindrome.java Rules Below

1. Read a line from the console and convert it to lower-case and then remove any character which not a digit, not a letter, and not white space (i.e., we need to keep the white space to do the split in the next step);

2. Convert the String into an array of Strings, using split(\\s+) as shown above;

3. Adapt your algorithm from the first problem to test for equality of arrays of Strings instead of individual Strings, using equals(...) as shown above;

4. Print out the array of words (this will help with debugging), and then your answer;

5. Demonstrate your code on the poem shown above and also on the sentence This is not a word palindrome! Remember that you have to type it all in one line without carriage returns; you may use the slash or not indicate the end of lines.

Complete the code

import java.util.Scanner; public class WordPalindrome { /* * TODO: Complete this method as per the requirements of the assignment handout. * Make sure not to change the function signature. */ public static boolean isWordPalindrome( String line ) { /*We are providing you with a list of punctuations that we will use to test your code. * make sure that you use this same list of punctuations only and not something else. */ char[] punctuation = { '.', ',', ';', ':', '?', '/', '\'', '\'', '!', '-', '~', '(', ')' }; } /* * DO NOT MODIFY THE MAIN FUNCTION. * ANY CODE THAT YOU WRITE, MUST BE * INSIDE THE isWordPalindrome function. * Any code that you write inside the main * function will not be marked and will be completely ignored. */ public static void main(String[] args) { // Print out welcome message System.out.println(" Welcome to the Word Palindrome Test Program!"); // Define a scanner for user input Scanner userInput = new Scanner(System.in); System.out.println(" Type in a sentence to be tested or Control-d to end:"); while(userInput.hasNextLine()) { String line = userInput.nextLine(); if(isWordPalindrome( line )) System.out.println("Word Palindrome!"); else System.out.println("Not a Word Palindrome!"); } System.out.println("bye!"); } // main() } 

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

Step: 3

blur-text-image

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

What are Electrophoresis?

Answered: 1 week ago

Question

LO3 Discuss the steps of a typical selection process.

Answered: 1 week ago