Write a static method processFile that takes a Scanner conta

Write a static method processFile that takes a Scanner containing an input file as a parameter and that prints the output file with certain lines underlined. The lines to be underlined will all begin with a period. The period should not be printed. You should print the text that follows the period on a line by itself followed by a line of dashes that is equal in length to the text that follows the period.

For example, given the following input file:

Your method should print the following output:

Notice that some of the input lines can be blank lines

Solution

ProcessFileTest.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;


public class ProcessFileTest {

   public static void main(String[] args) throws FileNotFoundException {
       File fileName = new File(\"D:\\\\inputfile.txt\");
       Scanner scan = new Scanner(fileName);
       processFile(scan);

   }
   public static void processFile (Scanner scan){
       String s=\"\";
       while(scan.hasNextLine()){
           s = scan.nextLine();
           if(s.startsWith(\".\")){
               System.out.println(s.substring(1,s.length()));
               System.out.println(\"--------------------\");
           }
           else{
               System.out.println(s);
           }
          
       }
   }
}

Output:

Statement of Purpose
--------------------
I didn\'t expect to major in computer science until I took cse142.
I liked it more than I expected and that got me hooked on cs.

High School Performance
--------------------
I got very good grades in high school, graduating in the top 10% of
my class.

College Performance
--------------------
I have done well in my college classes, with an overall gpa of 3.5.

Write a static method processFile that takes a Scanner containing an input file as a parameter and that prints the output file with certain lines underlined. Th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site