I am working on a Java application for my college class, and at one point in the program I am to ask the user to input an integer. I could just have the user input an integer, and if there is a problem, Like them putting in “abcdefg”, I could just have a try/catch statement with a loop. But a while back I created a custom class that takes care of this problem by itself calledInputValidator. It has a built in scanner and takes care of basically everything (checking to make sure it was actually an int, double, etc..) and in the main class you can simply set a value equal to one of the getter methods to make sure it is actually a valid input.
What I’m wondering is, do you think it would be considered “Lazy” of me by my professor, intuitive, or just unnecessary? This class could be useful for many things, but could also be considered “Wasting memory” (it also checks for double, and I in the program it just checks an int). I would like to use it, but I want to make sure this is a legitimate thing to do when it comes to programming in the classroom. Thank you in advance.
I’ve used my own classes for validating input as well. I don’t see it as a problem, it reduces the code you need to write elsewhere and you can let the class do the job for you. Your professor shouldn’t mind because he can clearly see you understand validating input.
Here you can see the class I use.