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

Four score and seven years ago our fathers brought forth on this continent a new

ID: 3671860 • Letter: F

Question

Four score and
seven years ago our
fathers brought forth
on this continent
a new
nation.

Then a call to textJustify(input,30); will output the following to the console:


Four score and seven years ago
our fathers brought forth on
this continent a new nation.

Let's assume that I limit the width parameter to a range of [30,300]. A lower limit of 30, so you will always have more than one word on each line. And an upper limit of 300, which could result in all words on one line.

Suggestion: Start by removing all the extra space from the text (there is a similar Exercise in text). Then calculate the number of spaces you need to add back in, to achieve the desired width, after your code calculates how many lines of output are required. No need for hyphenation, just add more space between words.

Be certain that what you submit passes the Java compiler and does produce some output. A few points is infinitely better than a zero.....

Here's a portion of my testing code:

/*
* Written by W.P. Iverson, February 2016, for CS210 class
* Bellevue College, Bellevue, WA
* no rights reserved, copyleft
*/

public class Chapter6 {
   public static void main(String[] args) throws FileNotFoundException {
       File spaces = new File("spaces.txt");
       Scanner input = new Scanner(spaces);
        textJustify(input ,30);          
   }
   // Additional methods added below:
}

Explanation / Answer

import java.io.*;

import java.util.*;

public class Chapter6 {

public static void main(String args[]) throws Exception {

File spaces = new Flie(“spaces.txt”);

Scanner s = new Scanner(spaces);

textJustify(s,30);

}

void textJustify(String s,int w)

{

s.trim();

StringBuilder sb = new StringBuilder();

String line = s.readLine();

while (line != NULL) {

for (w=30;w<=300;w++) {

FileWriter fw = new FileWriter(“text.txt”);

PrintWriter pw = new PrintWriter(pw);

pw.toString();

System.out.println(String.join(“ “,pw + lineSeparator());

}

}

}

s.close();

fw.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