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

Write a C program to run on unix to read a text file and print it...
Write a C program to run on unix to read a text file and print it to the display. It should count of the number of words in the file, find the number of occurrences of a substring, and take all the words in the string and sort them (ASCII order). You must use getopt to parse the command line. There is no user input while this program is running. Usage: mywords [-cs] [-f substring] filename • The -c flag...
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...
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...
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...
Assignment in C programming class: read the text file line by line, and place each word,...
Assignment in C programming class: read the text file line by line, and place each word, in order, in an array of char strings. As you copy each word into the array, you will keep a running count of the number of words in the text file and convert the letters of each word to lower case. Assume tgat you will use no more than 1000 words in the text, and no more than the first 10 characters in a...
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...
C Programming How do you read in a text file line by line into a an...
C Programming How do you read in a text file line by line into a an array. example, i have the text file containing: line 1: "qwertyuiop" line 2: "asdfghjkl" line 3: "zxcvbnm" Then in the resulting array i get this: array:"qwertyuiopasdfghjklzxcvbnm"
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT