Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this activity, you will practice with file I/O and exception handling. 1. Start a new project and name it FileIO. Copy the english text

In this activity, you will practice with file I/O and exception handling.

1. Start a new project and name it FileIO. Copy the english text and save the file in your project directory.

2. Open FileIO.java, add a new method as follow:

public static void copyFile(String fileName, String fileName2)

3. Implement this method, so that it reads each line from a file (named fileName) and writes it into a new file (named fileName2). Make sure that you use try catch block to handle the exceptions.

4. After you implement this method, add the following statement to the main() method and run your project.

copyFile("english.txt", "copy.txt");

If everything works, you should see a copy of the original file created in your project folder.

5. In your FileIO.java, add another method:

public static void translateFile(String fileName, String fileName2)

6. Implement this method, so that it reads lines from a file as input and translates each word to "Pig Latin". The rule is to convert a word by removing the first letter, placing that letter at the end of the word, and then appending "ay" to the word. Here is an example:

English: HOW ARE YOU

Pig Latin: OWHAY REAAY OUYAY

You will use String methods. If you are not familiar with the String class, browse its API here:

https://docs.oracle.com/javase/9/docs/api/java/lang/String.html (Links to an external site.)

In particular, read about the following methods:

  • subString(int index)
  • charAt(int index)

Hint: to concatenate two strings or a string with a character, you may use "+" sign.

7. After you implement this method, add the following statement in the main() method to test it:

translateFile("english.txt", "piglatin.txt");

If everything works, you should see a new file created in your project folder, and the content of the file is the pig latin version of the original file.

english.txt

WELCOME HELLO HOW ARE YOU LONG TIME NO SEE WHAT IS YOUR NAME WHERE ARE YOU FROM PLEASED TO MEET YOU GOOD MORNING GOOD EVENING GOOD NIGHT GOODBYE GOOD LUCK EXCUSE ME SORRY PLEASE THANK YOU

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

Step: 3

blur-text-image

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

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

Define psychology and cite its four major goals.

Answered: 1 week ago