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...
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.
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...
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...
Write a program that will read in from input file one line at a time until...
Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespaces, commas and periods....
C++ Parse text (with delimiter) read from file. If a Text file has input formatted such...
C++ Parse text (with delimiter) read from file. If a Text file has input formatted such as: "name,23" on every line where a comma is the delimiter, how would I separate the string "name" and integer "23" and set them to separate variables for every input of the text file? I am trying to set a name and age to an object and insert it into a vector. #include <iostream> #include <vector> #include <fstream> using namespace std; class Student{    ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT