Richard Tookey wrote:Why not just remove all spaces and hyphens from the input supplied by the user and from the keys
when generating the map.......... This way you just have to replace all spaces or hyphens with the empty string; a simple
one line regular expression.
Campbell Ritchie wrote: Start by reducing the main method to its ideal length: 1 statement. Create a class or some classes which will encapsulate your logic. One will have the Map as a field. Create methods to input the two numbers and the operator, and to do the calculation...........
Campbell Ritchie wrote:
Why are you trying................ Don't try to do the whole thing all at once. Do it in bits, and write
methods which test each part before the app is complete.
Richard Tookey wrote:Since you will only ever lookup an integer using the alpha representation of the integer you only need one
Map<String,Integer>. That use as key the normalised alpha representation with hyphens and spaces removed (a simple regex will do this)............
Sudhir Srinivasan wrote:
Richard Tookey wrote:Since you will only ever lookup an integer using the alpha representation of the integer you only need one
Map<String,Integer>. That use as key the normalised alpha representation with hyphens and spaces removed (a simple regex will do this)............
by way of a simple regex expression as suggested by Richard. Will post the same on completion.
Richard Tookey wrote:You don't need to modify the String[] containing the alpha representations!
Richard Tookey wrote:You just need to normalise each one when using it as a key in the Map! You normalise the String[]
entry when building the Map
Richard Tookey wrote:
and you normalise the user's input when looking up the value in the Map.
Sudhir Srinivasan wrote:
- attributes inherited from GetValues
- getter method 1:
.. Iteratively, for each String output [output being variable name] in the keySet of tempMap
.. check for String equality of user input 1[access & get superclass method] with output. If true..........
Sudhir Srinivasan wrote:Okay. I think I've got it.
Richard Tookey wrote:Though I can't see your latest code so I can't be certain....
Sudhir Srinivasan wrote:At the time of building the map object sendMap, by looping thru
the String[] str & adding the key-value pairs to this object,...Richard Tookey wrote:You
just need to normalise each one when using it as a key in the Map! You normalise the String[]
entry when building the Map...
Sudhir Srinivasan wrote:In the GetValues class, when setting the respective field
within the setter method,....Richard Tookey wrote:and you normalise the user's input
when looking up the value in the Map.
Sudhir Srinivasan wrote:In the MapTxtToInt class,
just set (& return) the (normalized) map object sendMap passed from
TestNaturalLanguageMultiply....
......check for String equality of normalized user input with that of the keySet
of the normalized map object.
Richard Tookey wrote:and you normalise the user's input when looking up
the value in the Map.
Sudhir Srinivasan wrote:The updated code snippets based on my understanding of your suggestions.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Sudhir Srinivasan wrote:The updated code snippets based on my understanding of your suggestions.
Sudhir,
It's too late for this thread, I suspect, but for future reference: Please DontWriteLongLines.
Sudhir Srinivasan wrote:Hi Winston,
I've edited my last post and shortened the lines as suggested.
I shall certainly keep your suggestions in mind when posting in the future. Any inconvenience caused to the moderators / responder(s)
is regretted.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Consider Paul's rocket mass heater. |