Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2. Write a Short Program –Reading and Writing a File The items that you will be

ID: 675556 • Letter: 2

Question

2. Write a Short Program –Reading and Writing a File

The items that you will be submitting to me are the following 4 things: your files - .java files (so I can see the source code), .class files, your output file and a screenshot of your code running (so I know your code is running or not running if that is the case). I do look at your code – so be forewarned. Points will be taken off if you do not include all these files. You can zip up your project folder and just attach one zip file if you like; the screenshot should be attached as a separate file.

Make sure your code includes all test cases necessary for your specific program. These should be evident in your screenshot(s).

Your assignment is to write a program that reads the attached text file and writes out a separate text file (using your first initial and last name as the filename). The new text file should contain all the same lines of text as the input file with the addition of a line number appended as the first character on the line.  

Ex: if your input line reads:

this is a test

your output should read

1. this is a test

chapter.txt File:

A long time ago, in a galaxy not so far, far away....
The University System of Georgia embarked on a mission to
merge SPSU with Kennesaw State University.
It is a period of transition. While
many remain skeptical, it is imperative to trust
The Force. The new U will emerge officially in Fall 2015
and rest assured that good will triumph over evil.
While the name of SPSU will be retired into history,
the spirit of the faculty, staff and students will
remain. As the new U arises, so will the power of the
spirit of SPSU in its new realm. So, as future custodians
of the spirit of SPSU, keep the faith and remain true ...
for now and always SPSU and Yoda Rock!

Explanation / Answer

package mani;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class Lottery {
public static void main(String[] args) throws IOException,FileNotFoundException {
   String iFile="C:\Users\MANIKANTA Reddy\Desktop\chegg\chapter.txt";
   BufferedReader br;
   int count=1;
   String k;
   br=new BufferedReader(new FileReader(iFile));
   BufferedWriter bw=new BufferedWriter(new FileWriter("C:\Users\MANIKANTA Reddy\Desktop\chegg\my.txt"));
   while((k=br.readLine())!=null){
       bw.write(Integer.toString(count));
       bw.write(".");
       bw.write(k);
       bw.newLine();
       count++;
   }
  
   bw.close();
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote