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: 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 5 6 7 E 8 9 10 11 12 13 G|G|S| | 14 15 16 17 18 19 A N D H A M 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 Formatted string: 012 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |B|E|A|C| H |A|L|I You will implement three static methods in a class named StringFormatter that is not shown.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
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
(a) Write the StringFormatter method totalLetters, which returns the total number of letters in
the words in its parameter wordList. For example, if the variable List<String> words is
["A", "frog", "is"], then the call StringFormatter.totalLetters (words) returns 7.
You may assume that all words in wordList consist of one or more letters.
Complete method totalLetters below.
/** Returns the total number of letters in wordList.
*
Precondition: wordList contains at least two words, consisting of letters only.
*/
public static int totalLetters (List<String> wordList)
Transcribed Image Text:(a) Write the StringFormatter method totalLetters, which returns the total number of letters in the words in its parameter wordList. For example, if the variable List<String> words is ["A", "frog", "is"], then the call StringFormatter.totalLetters (words) returns 7. You may assume that all words in wordList consist of one or more letters. Complete method totalLetters below. /** Returns the total number of letters in wordList. * Precondition: wordList contains at least two words, consisting of letters only. */ public static int totalLetters (List<String> wordList)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY