Parse a Numeric Toll-Log Timestamp
Problem statement
A toll-booth log line has four space-separated fields: timestamp licensePlate booth boothType. The timestamp is the number of seconds since the logging software started.
The interview report describes fixing a timestamp stored as text by using a numeric float. Its supplied LogEntry class already contains the repaired Float.parseFloat constructor and numeric getTimestamp method; the original erroneous code is unavailable.
For this exercise, implement a finite getTimestamp(logLine) wrapper: parse the first field as an IEEE 754 single-precision (binary32) numeric value, then return that same value through a double-precision return type. The other three fields do not affect the timestamp.
For this exercise, assume round-to-nearest with ties to even. The returned value reflects single-precision rounding, rather than preserving the exact decimal text. No repository editing or file I/O is required.
Function
getTimestamp(logLine: String) → doubleExamples
Example 1
logLine = "44776.619 KTB918 310E MAINROAD"return = 44776.6171875The source test parses 44776.619 as a Java float. Its binary32 numeric value is 44776.6171875, which the practice wrapper returns exactly as double.
Example 2
logLine = "52160.132 ABC123 400W ENTRY"return = 52160.1328125The second source test parses 52160.132 as a Java float, whose value is 52160.1328125.
Example 3
logLine = "0.125 A0 10E EXIT"return = 0.125One eighth is exactly representable in binary32.
Constraints
- For this exercise, assume a valid line with exactly four nonempty fields separated by single ASCII spaces, without leading or trailing spaces.
- The timestamp token is a nonnegative decimal from
0through100000, with1through6integer digits and optionally1through3fractional digits. Leading zeros are allowed; signs, exponent notation, NaN and infinity are excluded. - For this exercise, assume the complete line has at most
100characters and the other fields are valid toll-log tokens.