Raven Mad Libtxt Once upon a timeofday dreary while I word w

Raven Mad Lib.txt

Once upon a (timeofday) dreary, while I (word), weak and weary,
Over many a quaint and curious (noun) of forgotten lore—
While I nodded, nearly napping, suddenly there came a (verb),
As of some one gently rapping, rapping at my chamber (noun) .
“’Tis some (noun) ,” I muttered, “tapping at my chamber door—
Only this and nothing more.”

The Farm Mad Lib.txt

I spent last summer on my grandfather\'s (adjective) farm. He
raises oats, wheat, and (noun) . Grandfather also grows lettuce,
corn, and lima (pluralNoun) . My favorite place to (verb) on
the farm is the (noun) house where Grandfather keeps his
(adjective) chickens. Every day, each hen lays round, smooth
(pluralNoun) . Grandfather sells most of them, but keeps some so
the hens can (verb) on them and hatch cute, fuzzy little
(pluralNoun) for an hour, and climb a (noun).without losing your
(partofBody) . I\'m looking forward to next year, when Grandfather
is going to show me how to drive his (noun) , sow the
(noun) , and (verb) the cow.

Data files Raven Mad Libtxt The Farm Mad Lib txt The purpose of this file is to create a program that will read a Mad Lib e, allow the user to check for points to place the new words. Then output the result to a new text file. Words in the original file that need to be replaced begin and end with 0. For example, the first line of Raven Mad Lib txt looks like: Once upon a (timeofday) dreary, while I (word), weak and weary, A sample Execution of the code would look like the following: Please type in the name of the file The Farm Mad Lib txt Please type in the name of the output flle output.txt While reading your file I found (adjective), please type in the replacement fuzzy While reading your file I found (noun please type in the replacement fox While reading your file I found (verb), please type in the replacement kick Your file is done The output should be in output.txt Then in that file should be the replacement file. Notes For the file names, you will want to do nextLine() n case they use spaces All replacement words start and end with parenthesis. 0 so you know what to look for. So you will nee to both read and write from a file at the same time. Most of the time you will just read a word and then turn around and write it to a file. You don\'t need to worry about newline characters, your output can just be a single long line o You should not however have a single word per line o If you want to get fancy, you could put a newline character every 10th word.

Solution

Program:


import java.io.*;
import java.util.Scanner;

public class Replacement {
   public static void main(String args[]) throws IOException {
       int i;
       FileInputStream fin;
       FileOutputStream fout;
       BufferedReader reader = null;
       FileWriter fw=null;
       BufferedWriter bw=null;
       Scanner s=new Scanner(System.in);
       try {
           // open input file
           try {
               System.out.print(\"Please Type In the Name Of The File : \");
               fin = new FileInputStream(s.nextLine());
               reader = new BufferedReader(new InputStreamReader(fin));
           } catch (FileNotFoundException e) {
               System.out.println(\"Input File Not Found\");
               return;
           }
           // open output file
           try {
               System.out.print(\"Please Type In the Name Of The Output File : \");
               File f = new File(s.nextLine());
               fw = new FileWriter(f);
       bw = new BufferedWriter(fw);
           } catch (FileNotFoundException e) {
               System.out.println(\"Error Opening Output File\");
               return;
           }
       } catch (ArrayIndexOutOfBoundsException e) {
           System.out.println(\"Usage: CopyFile From To\");
           return;
       }
       // Copy File
       try {
           String line = reader.readLine();
           while(line != null){
               if(line.contains(\"(\"))
               {
                   String split[]=line.split(\" \");
                   for(int j=0;j<split.length;j++)
                   {
                       String val=split[j];
                       if(val.startsWith(\"(\") && val.endsWith(\"\"))
                       {
                           System.out.print(\"While Reading Your File I have found \"+val+\" please type in the replacement :\");
                           String newValue=s.nextLine();
                           bw.write(newValue);
                           bw.write(\" \");
                       }
                       else
                       {
                           bw.write(val);
                           bw.write(\" \");
                       }
                      
                          
                   }
               }
//System.out.println(line);
line = reader.readLine();
}
           System.out.println(\"Your File Is Done\");

           /*do {
               i = fin.read();
               if (i != -1)
                   fout.write(i);
           } while (i != -1);*/
       } catch (IOException e) {
           System.out.println(\"File Error\");
       }
       fin.close();
       bw.flush();
bw.close();
   }
}

Raven Mad Lib.txt Once upon a (timeofday) dreary, while I (word), weak and weary, Over many a quaint and curious (noun) of forgotten lore— While I nodded, nearl
Raven Mad Lib.txt Once upon a (timeofday) dreary, while I (word), weak and weary, Over many a quaint and curious (noun) of forgotten lore— While I nodded, nearl

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site