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

  Write the code1 one argument used to justify the fact that

write the code1. one argument used to justify the fact that the stack data structure in the standard library does not

  Program that tests if an input string is a palindrome

Write a recursive method that takes a string as argument and returns the reverse of the string (given the argument "Horse" your method should return the string "esroH").

  Inheriting from the jframe class

What is the difference between inheriting from the JFrame class and using a JFrame member variable?

  Write a method called range that returns the range of value

Write a method called 'range' that returns the range of values in an array of integers. The range is defined as 1 more than the difference between the maximum and minimum values in the array. For example, if an array called list contains the value..

  What is server-side and client-side scripting

What is Server-side and Client-side scripting - Explain the differences between server-side and client - side scripting languages.

  Program that allows users to enter a dollar amount

Write a program that allows users to enter a dollar amount for their bank account balance at the beginning of the month. Then ask the user to enter a dollar amount for any number of checks written in a month, up to 50.

  The application with all the specifications should be

the application with all the specifications should be developed based on a graphical user interface.1. implement proper

  Design a java program that simulates a slot machine

Design a java program that simulates a slot machine. When the program runs, it should do the following: Ask the user to enter the amount of money he or she wants to insert into the slot machine. ? Instead of displaying images, the program will random..

  Algorithm analysis with advanced data structures

Write a program to help the merchants devise a sequence of transmutations that would change silver into gold with the smallest possible total fee paid to the alchemists.

  Implement bounded partial queue using signaling mechanism

Can you explain the reason? You can run the experiments on ecen5033.colorado.edu. Submit the code as well as experimental results - Implement both these schemes in Java. Each of the methods foo() and bar() just sleeps for 20 milliseconds.

  Write a program to track hourly employee departure

A company hires you to write a program to track hourly employee arrival and departure times from work. In essence, you are tasked to make an online time clock.

  Implement a class student

Implement a class Student. For the purpose of this exercise, a student has a name and a total quiz score. Supply a suitable constructor and methods getName( ), addQuiz(int score), getTotalScore( ), and getAverageScore ( ).

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