4. This question involves the process of taking a list of words, called wordList, and producing a formatted string of a specified length. The list wordList contains at least two words, consisting of letters only. When the formatted string is constructed, spaces are placed in the gaps between words so that as many spaces as possible are evenly distributed to each gap. The equal number of spaces inserted into each gap is referred to as the basic gap width. Any leftover spaces are inserted one at a time into the gaps from left to right until there are no more leftover spaces. The following three examples illustrate these concepts. In each example, the list of words is to be placed into a formatted string of length 20. Example 1: wordList: ["AP", Total number of letters in words: 14 Number of gaps between words: 3 Basic gap width: 2 Leftover spaces: 0 Formatted string: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |A|P| | |C|O|M|P| | |S|C|1| | |R|O|C|K|S| с I Example 2: wordList: ["GREEN", "EGGS", "AND", "HAM"] Total number of letters in words: 15 Number of gaps between words: 3 Basic gap width: 1 Leftover spaces: 2 The leftover spaces are inserted one at a time between the words from left to right until there are no more leftover spaces. In this example, the first two gaps get an extra space. Formatted string: 0 1 2 3 4 G R E E N Formatted string: 012 3 4 A с H "COMP", "SCI", "ROCKS"] 5 B 6 Example 3: wordList: ["BEACH", "BALL"] Total number of letters in words: 9 Number of gaps between words: 1 Basic gap width: 11 Leftover spaces: 0 7 E 8 9 10 11 12 13 14 15 16 17 18 19 A N D G G S H A M 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 B 3|A|1 L L You will implement three static methods in a class named StringFormatter that is not shown.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
4. This question involves the process of taking a list of words, called wordList, and producing a formatted
string of a specified length. The list wordList contains at least two words, consisting of letters only.
When the formatted string is constructed, spaces are placed in the gaps between words so that as many spaces as
possible are evenly distributed to each gap. The equal number of spaces inserted into each gap is referred to as
the basic gap width. Any leftover spaces are inserted one at a time into the gaps from left to right until there are
no more leftover spaces.
The following three examples illustrate these concepts. In each example, the list of words is to be placed into
a formatted string of length 20.
Example 1: wordList: ["AP", "COMP", "SCI", "ROCKS"]
Total number of letters in words: 14
Number of gaps between words: 3
Basic gap width: 2
Leftover spaces: 0
Formatted string:
2
0 1
A
A|P| |
3
Basic gap width: 1
Leftover spaces: 2
Formatted string:
0
1
G R
Example 2: wordList: ["GREEN",
Total number of letters in words: 15
Number of gaps between words: 3
4
с
2 3 4
E N
Formatted string:
0
1 2
B
E
A
5 6
O M
3
4
7
P
The leftover spaces are inserted one at a time between the words from left to right until there are no more
leftover spaces. In this example, the first two gaps get an extra space.
5
H
8 9 10 11
T
S C
6 7
E
Example 3: wordList: ["BEACH", "BALL"]
Total number of letters in words: 9
Number of gaps between words: 1
Basic gap width: 11
Leftover spaces: 0
12 13 14 15 16 17 18
I
| | |R|0|C|
с
"EGGS", "AND", "HAM"]
8 9 10 11 12 13
G S
G||
| | |
A
19
K S
200
14 15 16 17 18 19
| D|H|1
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| |B|A|L|L|
You will implement three static methods in a class named StringFormatter that is not shown.
A
M
Transcribed Image Text:4. This question involves the process of taking a list of words, called wordList, and producing a formatted string of a specified length. The list wordList contains at least two words, consisting of letters only. When the formatted string is constructed, spaces are placed in the gaps between words so that as many spaces as possible are evenly distributed to each gap. The equal number of spaces inserted into each gap is referred to as the basic gap width. Any leftover spaces are inserted one at a time into the gaps from left to right until there are no more leftover spaces. The following three examples illustrate these concepts. In each example, the list of words is to be placed into a formatted string of length 20. Example 1: wordList: ["AP", "COMP", "SCI", "ROCKS"] Total number of letters in words: 14 Number of gaps between words: 3 Basic gap width: 2 Leftover spaces: 0 Formatted string: 2 0 1 A A|P| | 3 Basic gap width: 1 Leftover spaces: 2 Formatted string: 0 1 G R Example 2: wordList: ["GREEN", Total number of letters in words: 15 Number of gaps between words: 3 4 с 2 3 4 E N Formatted string: 0 1 2 B E A 5 6 O M 3 4 7 P The leftover spaces are inserted one at a time between the words from left to right until there are no more leftover spaces. In this example, the first two gaps get an extra space. 5 H 8 9 10 11 T S C 6 7 E Example 3: wordList: ["BEACH", "BALL"] Total number of letters in words: 9 Number of gaps between words: 1 Basic gap width: 11 Leftover spaces: 0 12 13 14 15 16 17 18 I | | |R|0|C| с "EGGS", "AND", "HAM"] 8 9 10 11 12 13 G S G|| | | | A 19 K S 200 14 15 16 17 18 19 | D|H|1 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |B|A|L|L| You will implement three static methods in a class named StringFormatter that is not shown. A M
(b) Write the StringFormatter method basicGapWidth, which returns the basic gap width as
defined earlier.
Class information for this question
public class StringFormatter
public static int totalLetters (List<String> wordList)
public static int basicGapWidth (List<String> wordList,
public static int leftoverSpaces (List<String> wordList,
int formattedLen)
public static String format (List<String> wordList, int formattedLen)
int formattedLen)
Transcribed Image Text:(b) Write the StringFormatter method basicGapWidth, which returns the basic gap width as defined earlier. Class information for this question public class StringFormatter public static int totalLetters (List<String> wordList) public static int basicGapWidth (List<String> wordList, public static int leftoverSpaces (List<String> wordList, int formattedLen) public static String format (List<String> wordList, int formattedLen) int formattedLen)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 6 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education