Answered You can hire a professional tutor to get the answer.

QUESTION

Submit Chapter6.java with a public static method named justifyText that accepts two parameters; a Scanner representing a file as the first parameter,...

Submit Chapter6.java with a public static method named justifyText that accepts two parameters; a Scanner representing a file as the first parameter, and an int width specifying the output text width.  Your method writes the text file contents to the console in full justification form (I'm sure you've seen this in Microsoft Word  full.docx ).  For example, if a Scanner is reading an input file containing the following text:

Four         score   andseven                          years ago                ourfathers brought                       forth             on this                              continenta                              new nation.

Then a call to justifyText(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.

Hint: Start by removing all the extra space from the text (a similar Exercise in text).  Then calculate the number of spaces you need to add back in, to achieve the desired width, then System.out the text one line at a time.  You may assume that we need to add only one or two spaces between words, and do not hyphenate words as other fancy programs might do.  Keep it simple (well it's not that simple).  And be certain that what you submit passes the Java compiler and does produce some output!!!  A few points is infinitely better than a zero.....

To run above example, I had the following file in my Eclipse project to read these data from the text: spaces.txt

Here's my test code:

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

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question