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

please answer 13th question Tin Test 2-Google Chrome https/A oodle- courses 161

ID: 3862365 • Letter: P

Question

please answer 13th question

Tin Test 2-Google Chrome https/A oodle- courses 161 7.wolfwa Ask me anything eduV mod/quiz/review.php? attempt :541505 inn 13 2.00 point cut question Compete 9.00 points out Comment Does not flip lines or print out results. Does use line processing. File I/O Write a method called wordwrap that accepts a scanner represent ng an input file and a PrintStream or an oulpul lie as PHI anu wr Les Eauh lima ol Lhe inpuL lila the culpu. file, word wrapping all nes that are longer than 60 characters. For example, if a line contains 112 characters, the method should replace it with two lines: one contairirg the first 00 characters and a her containing the linal 52 charact s. A line containing 217 characters should be wrapped intc four lines: three of length 60 and a final line of length 3/ public static void wordinrep (Scenner inpu PrintStream outout 011 -ha Next Comment 2: Does not output to given PrintStream. -11: Does not ocrrectly process lines each character is on a separate line. charAti 60 vvill cause a StringlndexOutotBoundsFxcaptian Array Method Write a method called append that accepts two integer arrays as parameters and returns a rew array that contains the result of appending the values stored in the secord array to the end of 59 PM 12/12/2016

Explanation / Answer

InputOutputFile.java

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


public class InputOutputFile {

  
   public static void main(String[] args) throws FileNotFoundException {
       File file = new File("D:\testing.txt");
       File output = new File("D:\output.txt");
      
       Scanner scan = new Scanner(file);
       PrintStream ps = new PrintStream(output);
       wordWrap(scan, ps);
   }
   public static void wordWrap(Scanner input, PrintStream output) {
       String line ;
       while(input.hasNextLine()){
           line = input.nextLine();
           int length = line.length();
           int startIndex = 0;
           if(length> 60){
               while(length>60){
                  
                   output.println(line.substring(startIndex, startIndex+60));
                       startIndex+=60;
                       length-=60;
               }
           }
           output.println(line.substring(startIndex, line.length()));
       }
       output.flush();
       output.close();
      
   }

}

Output:

testing.txt

Once upon a time, there was a very bad man.
He smelled funky, sang awful pop songs, and told annoying knock-knock jokes.
Nobody liked him. Then, one day, he slipped on some ice and died. Everyone was happy after that.
The end.

output.txt

Once upon a time, there was a very bad man.
He smelled funky, sang awful pop songs, and told annoying kn
ock-knock jokes.
Nobody liked him. Then, one day, he slipped on some ice and
died. Everyone was happy after that.
The end.