Statistics

Problem Statement for "Sentence"

Problem Statement

Class name: Sentence
Method name: fix
Parameters: String
Returns: String

Implement a class Sentence, which contains a method fix.  fix returns the
result of a series of transformations on the input string described below.  The
input is a sentence, using only letters and spaces, with a period allowed only
if it is the last character.

*Capitalize the first letter of the first word, if it is not already  (The
first character of the first word is the first non-space character).

*Compress any consecutive spaces into one space and remove any spaces at the
beginning or end of the sentence (remove all spaces before the first non-space
character and after the last non-space character).

*Finally, ensure that there is period at the end of the sentence.  If not,
append a period to the end of the sentence.

Process rules from first to last.  

Here is the method signature (be sure your method is public):
String fix(String input)

input is at most 50 characters, contains letters, spaces, and possibly ends
with a period.  It contains at least one letter.

Examples:
"This is correct." returns "This is correct."
"this  is  wrong" returns "This is wrong."
"   another test    " returns "Another test."
"   another test   ." returns "Another test ."
"         a       ." returns "A ."

Definition

Class:
Sentence
Method:
fix
Parameters:
String
Returns:
String
Method signature:
String fix(String param0)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: