Just writing help on the title doesn't inform us what you need help with.
First before the try catch block, save the data in variables.
Then create another file
Name it as functions.java or something.
There create functions like isValidAge() which returns null if valid or something like " Enter age between X and Y range" or instead you can just return boolen based on how you want to deal with it. You can also use inbuilt functions of you wanna do basic check of weather a value is all string or alpha numeric.
Basically the point of this is that you will make the code cleaner and if you have to reuse it, it makes it easier.
Now this is all to check if the user input data is valid.
Then to handle the logic of what you wanna do with that data, u can use if else statement.
Hi! Thank you helping me, it actually worked. Thank you so much. But still I have few questions and problems. My problem is the app crashes ifa string is empty, example: if I wont put any on Age it crashes. How to solve it
2
u/paridhi774 Sep 14 '22 edited Sep 14 '22
Just writing help on the title doesn't inform us what you need help with.
First before the try catch block, save the data in variables.
Then create another file
Name it as functions.java or something.
There create functions like
isValidAge()which returnsnullif valid or something like " Enter age between X and Y range" or instead you can just return boolen based on how you want to deal with it. You can also use inbuilt functions of you wanna do basic check of weather a value is all string or alpha numeric.Basically the point of this is that you will make the code cleaner and if you have to reuse it, it makes it easier.
Now this is all to check if the user input data is valid.
Then to handle the logic of what you wanna do with that data, u can use if else statement.