Question

In: Computer Science

Design a program that will read each line of text from a file, print it out...

Design a program that will read each line of text from a file, print it out to the screen in forward and reverse order and determine if it is a palindrome, ignoring case, spaces, and punctuation. (A palindrome is a phrase that reads the same both forwards and backwards.)

Example program run:

A Toyota's a Toyota
atoyoT a s'atoyoT A
This is a palindrome!

Hello World
dlroW olleH
This is NOT a palindrome!

Note:

You are only designing the program at this point.

Submit:

Pseudocode demonstrating your program plan.

Function prototypes with description and pre/post conditions.

Running shell program

Solutions

Expert Solution

Below is the required code snippest:

  1. import java.io.*;
  2. public class Palindromechecker
  3. {
  4.                     public static void main (String [] args) throws IOException
  5.                     {
  6.                                          BufferedReader File = new BufferedReader (new FileReader ("input.txt"));
  7.                                          String line;
  8.                                          line = File.readLine();
  9.                                          String st, another = "y";
  10.                                          int left, right;
  11.                                          String newSt = "";
  12.                                          while(line != null)
  13.                                          {
  14.                                                              System.out.println(line);
  15.                                                              line = File.readLine(); //reads next line
  16.                                          }
  17.                                          PrintWriter outputFile = new PrintWriter (new FileWriter("output.txt"));
  18.                                          outputFile.println("palindrome string ");
  19.                                          File.close();
  20.                                          outputFile.close();
  21.                                          while (another.equalsIgnoreCase("y"))                       {
  22.                                                              st = File.readLine();
  23.             left = 0;
  24.             right = st.length() - 1;
  25.         while (st.charAt(left) == st.charAt(right) && left < right)
  26.                                          {
  27.               left++;
  28.               right--;
  29.          }
  30.          System.out.println();
  31.             if (left < right)
  32.             System.out.println ("NOT palindrome string");
  33.             else
  34.             System.out.println ("palindrome string");
  35.             System.out.println();
  36.             another = File.readLine();
  37.                                          }
  38.    }
  39. }

Thank you.


Related Solutions

Complete the program to read in values from a text file. The values will be the...
Complete the program to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows) and the number...
You have to write a program that will read an array from a file and print...
You have to write a program that will read an array from a file and print if the numbers in the file are right truncatable primes. A right truncatable prime is a prime number, where if you truncate any numbers from the right, the resulting number is still prime. For example, 3797 is a truncatable prime number number because 3797, 379, 37, and 3 are all primes. Input-Output format: Your program will take the file name as input. The first...
Please write a java program to write to a text file and to read from a...
Please write a java program to write to a text file and to read from a text file.
Design and write a python program that reads a file of text and stores each unique...
Design and write a python program that reads a file of text and stores each unique word in some node of binary search tree while maintaining a count of the number appearance of that word. The word is stored only one time; if it appears more than once, the count is increased. The program then prints out 1) the number of distinct words stored un the tree, Function name: nword 2) the longest word in the input, function name: longest...
Write a C++ program to open and read a text file and count each unique token...
Write a C++ program to open and read a text file and count each unique token (word) by creating a new data type, struct, and by managing a vector of struct objects, passing the vector into and out of a function. Declare a struct TokenFreq that consists of two data members: (1) string value; and (2) int freq; Obviously, an object of this struct will be used to store a specific token and its frequency. For example, the following object...
C++ Write a whole program to read 50 salaries from the file “Salaries.txt” and print them...
C++ Write a whole program to read 50 salaries from the file “Salaries.txt” and print them on the screen (each value on a separate line), you have to also save the grades (each value on a separate line) into another file “SalariesWithBonus.txt” after you add a bonus of two percent to each salary (example For the salary 100000 a bonus of 2000 will be added as 100000 X 0.02 = 2000). Your code should check whether the file “Salaries.txt” opened...
(C++) Write a program to read from a grade database (data.txt). The database (text file) has...
(C++) Write a program to read from a grade database (data.txt). The database (text file) has students names, and grades for 10 quizzes.Use the given function prototypes to write the functions. Have main call your functions. The arrays should be declared in main() and passed to the functions as parameters. This is an exercise in parallel arrays, int and char 2 dim arrays. Function prototypes: int readData(ifstream &iFile, int scores[][10], char names[][30]); This functions takes the file stream parameter inFile...
Python program: Write a program that reads a text file named test_scores.txt to read the name...
Python program: Write a program that reads a text file named test_scores.txt to read the name of the student and his/her scores for 3 tests. The program should display class average for first test (average of scores of test 1) and average (average of 3 tests) for each student. Expected Output: ['John', '25', '26', '27'] ['Michael', '24', '28', '29'] ['Adelle', '23', '24', '20'] [['John', '25', '26', '27'], ['Michael', '24', '28', '29'], ['Adelle', '23', '24', '20']] Class average for test 1...
Write a C++ program that reads integers from standard input until end of file. Print out...
Write a C++ program that reads integers from standard input until end of file. Print out the largest integer that you read in, on a line by itself. Any erroneous input (something that is not an integer) should be detected and ignored. In the case where no integers are provided at all, print NO INTEGERS and stop. The whole program is under 40 lines of code. Just read from cin. Now, you need to detect non integers. In this case,...
Write a program Median.java to read each file whose name is specified in the command-line arguments....
Write a program Median.java to read each file whose name is specified in the command-line arguments. That is, for each command-line argument, open it as a file and read it. The file contents are zero or more lines each containing a list of comma-separated integers, such as 1,2,3,4 or 99,120,33. You should parse each of these integers and save them in an ArrayList (if you prefer you may use an array, but an ArrayList is likely to be easier for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT