Hello everybody,
i wanted to ask, to the holy and patients ones, to take a look at this code and help me, if possible, with some questions.
This is a program i'm creating to help me learn and remember various method of
String and String Builder.
The program asks the user to insert a String, then asks to answer correctly on the result of a given String method
(indexOf in code reported) applied to the string inserted. If the answer is not type-correct (in indexOf has to be a number)
the program asks the same question again.
The value of the parameters are created dinamically based on the string inserted by the user.
The code works fine.
My questions are about the better way (if there is a better way) to implement this code.
After editing three times (cursed the back button of the browser grrrrrr...), i've tried to lighten the most the topic.
Hope it's a bit better.
Ok, here is the code:
Now, here the questions. One last premise. I'm trying to learn to code properly, so i'd like to understand if my choices are correct. Here the question/doubts.
1 - in method checkAnswerInput() (which controls if the user has typed a number and not a letter),
there are two different implementations i've made to call back again the question, one with switch
and one with if else. I've heard that it's not good to use switch, but in this case i think
is the better solution. What do you think?
Are there other possible solutions to overcome this problem?
2 - In the four method that calls String methods (indexOfParamInt...() etc.) there is an if construct that repeats itself.
is there a possibility to use a method instead of four repetitions?
the point is that i need a return statement inside the method, only if the user typed a letter,
but if i create a method to handle the task, the return statemente works on the outside method,
not on the calling method. are there other possibilities to do this?
ok, for now that's it..
sorry if the questions seems dumb, probably they are.
if someone wants to give me feedback in general, they are more than welcome
thank you for the attention