|I need software that can read written numbers and convert them to integers.
The numbers are always between 1 and 99 inclusive, but may be misspelled.
The correct spelling of numbers is given by the following grammar, in which
'<' '>' '::=' and '|' are metacharacters and all others are literal:|
Create a class Speller that contains a method value that is given a String number
and that returns the integer value whose correct spelling is closest to number.
The distance between two spellings is defined to be the number of characters in one
of the spellings that would need to be changed to a different character in order
to make them match, where matching is case sensitive. Two spellings of different lengths are considered
to be infinitely far apart.
<NUMBER> ::= <ONES> | <TEEN> | <TENS> | <TENS>-<ONES>
<ONES> ::= one | two | three | four | five | six | seven | eight | nine
<TEEN> ::= ten | eleven | twelve | thirteen | fourteen | fifteen |
sixteen | seventeen | eighteen | nineteen
<TENS> ::= twenty | thirty | forty | fifty | sixty | seventy | eighty | ninety
The method should return -1 if there is more than one value that is closest to number.