Statistics

Problem Statement for "Datatype"

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 String, var, and classifies it into one of the above four types, and returns the datatype as a String.

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

  1. "123"

    Returns: "INTEGER"

  2. "324.1"

    Returns: "DECIMAL"

  3. ".12"

    Returns: "DECIMAL"

  4. "453."

    Returns: "DECIMAL"

  5. "770.555.1212"

    Returns: "STRING"

  6. "TrUe"

    Returns: "BOOLEAN"

  7. "this is just a string"

    Returns: "STRING"

  8. "453 ducks flew 4739.45 miles."

    Returns: "STRING"

  9. "."

    Returns: "DECIMAL"

  10. "false"

    Returns: "BOOLEAN"

  11. "True"

    Returns: "BOOLEAN"

  12. "0000"

    Returns: "INTEGER"

  13. "TRUES"

    Returns: "STRING"

  14. "cow.x"

    Returns: "STRING"

  15. "1a4"

    Returns: "STRING"

  16. "123.123."

    Returns: "STRING"

  17. "trUe"

    Returns: "BOOLEAN"

  18. "TruE"

    Returns: "BOOLEAN"

  19. "128.11.11"

    Returns: "STRING"

  20. ".e"

    Returns: "STRING"

  21. "FALSETRUE"

    Returns: "STRING"

  22. "9.a9"

    Returns: "STRING"

  23. "STRING"

    Returns: "STRING"

  24. "12345678911234567891123456789112345678911234567891"

    Returns: "INTEGER"

  25. "========.======="

    Returns: "STRING"

  26. "3.4.7"

    Returns: "STRING"

  27. "%"

    Returns: "STRING"

  28. "9999999999999999999999999999999"

    Returns: "INTEGER"

  29. "@#$.@#$"

    Returns: "STRING"

  30. "."

    Returns: "DECIMAL"

  31. "4 5"

    Returns: "STRING"

  32. "0"

    Returns: "INTEGER"

  33. "a.a"

    Returns: "STRING"

  34. " true"

    Returns: "STRING"

  35. "-15"

    Returns: "STRING"

  36. "TRUE"

    Returns: "BOOLEAN"

  37. "1..2"

    Returns: "STRING"


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: