Question: Finish writing the basicGapWidth method below so that it returns the size that the gap should be. The main method below will test your code

Finish writing the basicGapWidth method below so that it returns the size that the gap should be. The main method below will test your code to check that you solved it correctly.

import java.util.*; public class StringFormatter { /** Returns the basic gap width when wordList is used to produce * a formatted string of formattedLen characters. * Precondition: wordList contains at least two words, consisting of letters only. * formattedLen is large enough for all the words and gaps. */ public static int basicGapWidth(List wordList, int formattedLen) { }

public static int totalLetters(List wordList) { int numLetters = 0; for (String s : wordList) { numLetters = numLetters + s.length(); } return numLetters; }

public static void main(String[] args) { List wordList = new ArrayList(); wordList.add("AP"); wordList.add("COMP"); wordList.add("SCI"); wordList.add("ROCKS"); System.out.println("Should print 2 and prints: " + basicGapWidth(wordList,20));

Listwords2 = new ArrayList(); words2.add("GREEN"); words2.add("EGGS"); words2.add("AND"); words2.add("HAM"); System.out.println("Should print 1 and prints: " + basicGapWidth(words2,20));

Listwords3 = new ArrayList(); words3.add("BEACH"); words3.add("BALL"); System.out.println("Should print 11 and prints: " + basicGapWidth(words3,20)); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!