Write and test a java program to read in multiple lines

Assignment Help JAVA Programming
Reference no: EM13757949

A palindrome is defined as a string of 1 or more characters that contains a word, a phrase or a number that reads the same forward and backward, ignoring case, punctuation and white space.

Your assignment is to write and test a Java program (Project8.java) to read in multiple lines of input until an empty line is read. After each line is read, determine if the line contains a palindrome and, if it does contain a palindrome, print which type of palindrome it is (word, phrase, or number).

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.
public static String getInputLine ( )
Prompt the user to input a line of input and then read and return the line.
public static boolean isEmptyLine(String str)
Return TRUE if the parameter is empty or FALSE otherwise.
public 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.
public static String getPalType (String str)
Determine the type of the palindrome and return either "word", "phrase", "number".
The definition is number is all digits, a word is all alphabetic, and a phrase is anything else.
isPalindrome pseudo-code
Note: in the following, the symbol ß represents assignment
left ß 0
right ß position of last character in string
okay ß true
while okay and left < right
ch1 ß character in the string at position (left)
if ch1 is not a digit or letter
increment left
else
ch2 ß character 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
Here are the restrictions on this method. If you follow the logic above, then you will meet all the restrictions.
1. You may NOT return from the inside of a loop.
2. You may NOT break from the inside of a loop.
3. You should make the code as efficient as possible by stopping the processing as early as possible (when you find that it is or is not a palindrome).

Reference no: EM13757949

Questions Cloud

Genesis of health management information systems : The genesis of Health Management Information Systems (HMIS) goes back to the roots of numerous areas, including:
Need to create a pyramid with first name robert : Need to create a pyramid with first name Robert inside of a method named namePyramid and the print out to the console should look like this: Disregard the periods: I needed them to move the pyramid over
Analyze short-run and long-run cost functions : Analyze short-run and long-run cost functions - Evaluate the profit-maximizing price and output level for given operating costs for monopolies and firms in competitive industries.
Ow would the impact have changed without that information : What is the significance of placing "Song for a Dark Girl" in the South? How would the impact have changed without that information? That is only one example.
Write and test a java program to read in multiple lines : A palindrome is defined as a string of 1 or more characters that contains a word, a phrase or a number that reads the same forward and backward, ignoring case, punctuation and white space.
How to make conflicting opinions more fruitful : The Believing Game and How to Make Conflicting Opinions More Fruitful. The Believing Game is about making the effort to "believe" - or at least consider - the reasons for an opposing view on an issue.
Aspects of the regulatory environment : Write a paper that describes the main aspects of the regulatory environment which will protect the public from fraud within corporations, Pay particular attention to SOX requirements.
What is issue when working with a many-to-many relationship : What are some issues when working with a many-to-many relationship. Provide some examples.
Calculate the total consumer surplus : Using the following information for individuals and their willingness to pay for a bottle of ginger ale, calculate the total consumer surplus at a market price of $5.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd