Problem Statement
You are given a message string and you are required to reformat it.
DEFINITION
You must define public class Reformatter with public method String[] getReformatted(String message). message contains between 1 and 50 characters, inclusive, and does not contain leading, trailing or consecutive spaces.
String message contains one or more parts, where each part contains letters ('a'-'z', 'A'-'Z'), digits ('0'-'9'), and characters '/' and '='. Consecutive parts are separated by one space (' ') character.
Define a method String reformat(String part). The method reformats part using one of the following rules, in order of preference.
- If part is formatted "ab/cd" where each a, b, c and d is a digit ('0'-'9'), the method returns the result of division ab by cd rounded to exactly 6 digits after the decimal point according to standard rounding rules. For example, if part = "01/09", the return is "0.111111", and if part = "18/07", the return is "2.571429". If cd is "00", the return is "division by zero".
- If part.toLowerCase() is equal to "true=1" or to "false=0", the method returns "boolean".
- If part starts with one or more occurrences of "abc", continues with one or zero uppercase letter ('A'-'Z') and ends with zero or more occurrences of "z" (for example, "abcabcabc" or "abcXz"), the method returns "type1".
- If part consists of lowercase letters ('a'-'z') only, the method returns "lowercase".
- If part consists of uppercase letters ('A'-'Z') only, the method returns "uppercase".
- If none of the above holds, the method returns "unknown".
Get all parts from message and apply the described function to each part. Return a String[] with each element being the result of reformat for one part. The order of elements should be the same as the order of parts in message.
Definition
- Class:
- Reformatter
- Method:
- getReformatted
- Parameters:
- String
- Returns:
- String[]
- Method signature:
- String[] getReformatted(String message)
- (be sure your method is public)
Constraints
- message will contain between 1 and 50 characters, inclusive.
- Each character of message will be a letter ('a' - 'z', 'A' - 'Z'), a digit ('0' - '9') or one of characters '=', '/', ' '.
- message will contain no leading, trailing, or consecutive spaces.
Examples
"01/09 18/07 true=1 false=0 abcabcabc abcXz"
Returns: {"0.111111", "2.571429", "boolean", "boolean", "type1", "type1" }Examples from the problem statement. Note that "abcabcabc" corresponds to both returns "type1" and "lowercase", but "type1" must be returned because it corresponds to the item with lower number."05/5 06/66 abca zzzzzzzzz abcYYzz abcYz"
Returns: {"unknown", "0.090909", "lowercase", "lowercase", "unknown", "type1" }The return for "05/5" is "unknown" because it's formatted not "ab/cd", but "ab/c" (where a, b and c are digits). The return for "06/66" is 6 / 66 that is 0.090909 when rounded to 6 digits after the decimal point. Each of the parts "abca", "zzzzzzzzz", "abcYYzz" is close to "type1", but not exactly matches the description of "type1" ("abca" contains just "a" instead of complete second occurrence of "abc", "zzzzzzzzz" does not contain occurrences of "abc" at all and "abcYYzz" contains two uppercase letters in the middle, but only at most one is allowed). So the return for "abca" and "zzzzzzzzz" is "lowercase", and the return for "abcYYzz" is "unknown" (because it contains both lowercase and uppercase letters). The return for last part is "type1" because it exactly matches the description of "type1"."TrUe=1 TRUE=1 true=1 FalsE=0 FALSE=0"
Returns: {"boolean", "boolean", "boolean", "boolean", "boolean" }The first three parts equals to "true=1" if you ignore the case of the letters, and the last two parts equals to "false=0"."true = 1 false = 0"
Returns: {"lowercase", "unknown", "unknown", "lowercase", "unknown", "unknown" }There are 6 parts in this case: "true", "=", "1", "false", "=", "0". The return for "true" and "false" is "lowercase", and the return for other parts is "unknown"."012/23 123/00 9/00 12/00 1/00 0/0 00/00 12/0"
Returns: {"unknown", "unknown", "unknown", "division by zero", "unknown", "unknown", "division by zero", "unknown" }The parts "012/23", "123/00", "9/00", "1/00", "0/0" and "12/0" are not formatted "ab/cd", so the return is "unknown" for them. The parts "12/00" and "00/00" are properly formatted and the return for them is "division by zero".