Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Text Processing Exercise how can I write method TextCapsNocaps that takes a string argument and returns a string. This method will throw IllegalArgumentException if the

Text Processing Exercise

how can I write method TextCapsNocaps that takes a string argument and returns a string.

This method will throw IllegalArgumentException if the passed string argument has any formatting errors and explain the issue in the exception block.

The format for the argument is: : Where should be a positive integer number followed by a colon character ':' and a space, then are the characters to process.

Valid exp:

"2: Qwerty 123 aSdFg &*()"

Invalid strings example:

"8.2: Now is the time" "EE: For all good men"

"-5: Oops"

first example: 8.2 is not an integer.

second example: EE is not even close to being an integer.

third example: the integer is negative.

The number represents how many lower-case characters should be in between upper-case characters in the returned string.

This counting must only include alphabetic characters (A-Z, a-z).

(Other characters and white-space is not included in this counting.)

Examples:

"2: QWERTYUIOP" "QweRtyUioP"

"2: q*w*e r t$y$u.i.o,p" "Q*w*e R t$y$U.i.o,P"

In both cases, the returned string has every third letter in caps while the non-alphabetic characters are just inserted into the returned string as is.

There is one other twist to this exercise.

The string processing support the following three HTML-style directives:

- lc is for lower case. All alphabetic between these two must be in lower-case.

-uc is for upper case. All alphabetic between these two must be upper-case.

-<1c> 1c is for the first letter of each word being upper case while all other letters are lower case.

The characters outside of these HTML-style directives are still subject to the standard processing.

Exp:

"2: <1c>NOW IS THE TIME FOR ALL GOOD WOMEN. qwerty" "Now Is The Time For All Good Women. QweRty"

"1: The quick brown fox jumped over the lazy dog." "THE QUICK BROWN fox jumped over THE LAZY DOG."

The method do thorough error checking on the HTML-style directives:

"<" without matching ">"

Not one of the three supported directives.

Directive without the associated end-directive.

Nesting of the directives is allowed but the end-directives must appear in the opposite order.

Failures on any of the above must throw IAE with a descriptive message for the problem.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions