Problem Statement
When reading data as a string of characters, it is often useful to convert the data into a different datatype, which is easier to work with than a string of characters. For example, many operations are made much easier if the string of characters "123" is converted from a string of characters into a different datatype, such as an int or a float. We want to determine the best datatype to use for some data, given a string of characters. For the purposes of this problem, we will consider converting a string of characters into one of 4 datatypes:
- "INTEGER" - if the string consists only of the digits '0' - '9'.
- "BOOLEAN" - if the string is "true" or "false" (ignoring case)
- "DECIMAL" - if the string contains only digits '0' - '9', and exactly one decimal point ('.'). "123.12", ".123", and "124." are all of type "DECIMAL". Note that by this definition the string "." is classified as a "DECIMAL"
- "STRING" - if the string is none of the other datatypes.
Your task is to write a class Datatype with a method getType that takes a
Definition
- Class:
- Datatype
- Method:
- getType
- Parameters:
- String
- Returns:
- String
- Method signature:
- String getType(String var)
- (be sure your method is public)
Constraints
- var will contain between 1 and 50 characters, inclusive.
- Each character in var will be a letter ('a'-'z' or 'A'-'Z'), a digit ('0'-'9'), a decimal point ('.'), a space (' '), or one of the following characters: ,/<>?;':"[]{}\|`~!@#$%^*()_+-=&
Examples
"123"
Returns: "INTEGER"
"324.1"
Returns: "DECIMAL"
".12"
Returns: "DECIMAL"
"453."
Returns: "DECIMAL"
"770.555.1212"
Returns: "STRING"
"TrUe"
Returns: "BOOLEAN"
"this is just a string"
Returns: "STRING"
"453 ducks flew 4739.45 miles."
Returns: "STRING"
"."
Returns: "DECIMAL"
"false"
Returns: "BOOLEAN"
"True"
Returns: "BOOLEAN"
"0000"
Returns: "INTEGER"
"TRUES"
Returns: "STRING"
"cow.x"
Returns: "STRING"
"1a4"
Returns: "STRING"
"123.123."
Returns: "STRING"
"trUe"
Returns: "BOOLEAN"
"TruE"
Returns: "BOOLEAN"
"128.11.11"
Returns: "STRING"
".e"
Returns: "STRING"
"FALSETRUE"
Returns: "STRING"
"9.a9"
Returns: "STRING"
"STRING"
Returns: "STRING"
"12345678911234567891123456789112345678911234567891"
Returns: "INTEGER"
"========.======="
Returns: "STRING"
"3.4.7"
Returns: "STRING"
"%"
Returns: "STRING"
"9999999999999999999999999999999"
Returns: "INTEGER"
"@#$.@#$"
Returns: "STRING"
"."
Returns: "DECIMAL"
"4 5"
Returns: "STRING"
"0"
Returns: "INTEGER"
"a.a"
Returns: "STRING"
" true"
Returns: "STRING"
"-15"
Returns: "STRING"
"TRUE"
Returns: "BOOLEAN"
"1..2"
Returns: "STRING"