Question: In this assignment, you are to determine if an input string is a palindrome and, if it is, what type of palindrome. A palindrome for

In this assignment, you are to determine if an input string is a palindrome and, if it is, what type of palindrome. A palindrome for this assignment is defined as a number, word or phrase consisting of alphanumeric characters that reads the same frontwards and backwards while ignoring case, punctuation and white space.

For this assignment, create a package named assign1 and name your file Assign1.java.

UML Class Diagram:

+ main (String []): void - getInputLine (): String - isPalindrome (String): boolean - isEmptyLine (String): boolean - getPalType (String): Stri

Notes on the UML Class Diagram

There is only one class, Assign1.

Underlining the name of the variable/method in a UML class diagram indicates that

the variable or method is static. This means that all methods are static.

There are no class level variables.

The main is public while the other methods are private.

Limitations on Java Classes

For this assignment, you are limited to the following Java library classes.

1. Scanner 2. String 3. Character

Required main function: Here is the main method. Copy this into your code and do not change it.

 public static void main (String [] args) { 
 String line = getInputLine(); while (!isEmptyLine (line)) { 
 if (isPalindrome (line)) System.out.println ("\"" + line + 
 "\" is a palindrome and a " + getPalType (line)); else 
 System.out.println ("\"" + line + "\" is not a palindrome"); line = getInputLine(); 

}

 System.out.println ("End of program"); } 

Required methods: You must write the following methods as specified to complete your program. Pay attention to the name, return type and parameters.

private static String getInputLine ( ) 

Prompt the user to input a line of input and then read and return the line.

private static boolean isEmptyLine(String str)

Return true if the parameter is empty or false otherwise.

private static boolean isPalindrome (String str)

Return true if the string is a palindrome or false otherwise. See the pseudo-code on the next page for the logic and the restrictions on this implementation.

private static String getPalType (String str)

Determine the type of the palindrome and return word, phrase, or number. The definition is

number: only digits with white space and/or punctuation

word: only alphabetic with no white space and/or punctuations

phrase: anything else.

isPalindrome pseudo-code

Note: in the following, the symbolrepresents assignment

left0 rightposition of last character in string okay true while okay and left < right

ch1character in the string at position (left) if ch1 is not a digit or letter

increment left else

ch2character in the string at position (right)

if ch2 is not a digit or letter decrement right

else convert both ch1 and ch2 to upper case if ch1 = ch2

increment left

decrement right else

okay false endif

endif endif

end while return okay

Coding Restrictions

You may NOT return from or break from the inside of a loop.

You may NOT copy the String to another String.

You must STOP processing as early as possible (when you find that it is or is not a

palindrome).

Submitting

Using the link on Blackboard, submit your Assign1.java file for grading. It will be downloaded, compiled and graded as well as checked against the online utility to check for plagiarism and similarity to other students work.

Sample input and output

Enter a line of input: This is a test This is a test is not a palindrome 
Enter a line of input: 12345.4321 12345.4321 is a palindrome and a number. 
Enter a line of input: Otto! Otto! is a palindrome and a phrase. 

Enter a line of input: Able was I, ere I saw Elba. Able was I, ere I saw Elba. is a palindrome and a phrase.

Enter a line of input: Abba Abba is a palindrome and a word. 
Enter a line of input: Program complete 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!