Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pig Latin Program Write a program that translates normal text to pig latin. This program utilizes some of the string processing we studied in Chapter

Pig Latin Program

Write a program that translates normal text to pig latin. This program utilizes some of the string processing we studied in Chapter 9, and some file I/O (mostly from Chapter 4).

Basic Program Processing

The program asks the user for a file that contains text. Here the file name is "times.txt":

image text in transcribed

and then puts the translated text into a file that is a variation of the original file name -- the file's name, before the suffix ".txt", has the "-piglatin" appended to it. For this example, that would be "times-piglatin.txt" (your program creates this file). Once your program has put the translated text into the output file, it presents the following confirmation message:

image text in transcribed

Original "times.txt" file contents:

The New Times was on sale today for one dollar.

I bought a copy to read the lead story! It was very interesting.

The "times-piglatin.txt" file created by your program:

heTay ewNay imesTay asway noay alesay odaytay orfay neoay ollarday. Iay oughtbay aay opycay otay eadray hetay eadlay torysay! tIay asway eryvay nterestingiay.

Translation details:

This is a fairly simple PigLatin translation -- just take the first letter of the word and move to the end of the word, then add "ay".

Keep the line structure (i.e., the same number of words per line). Extra spaces between words can be lost, but line breaks and empty lines need to be maintained.

A sentence will end with at most one punctuation symbol, which will be one of these: .!? Don't let the punctuation get buried in the middle of the translated word (i.e., make sure it is still at the end of the word when translated).

If a word starts with an uppercase letter, it would be nice if your code kept the first letter uppercase (but it is OK if it buries the uppercase letter in the middle of the word).

Assume the text does not contain non-character words, such as numbers like 501 or monetary values such as $1.00.

Handle Special Situations

If the input file does not exist, then display the following error message:

image text in transcribed

image text in transcribed

The file name MUST end in ".txt". If the file name does not, then report an error and exit the program:

image text in transcribed

image text in transcribed

Do not automatically overwrite the output file. If the output file already exists, then you must ask the user if it is OK to overwrite it, and only overwrite it if you get a response of 'y' or 'Y' -- otherwise, just exit the program without doing any pig latin translation:

image text in transcribed

Other Requirements

Put your solution in a file named PigLatinTranslator.java

Input Give the name of the file to translate times.txt OK Cancel

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

8. Do the organizations fringe benefits reflect diversity?

Answered: 1 week ago