I have a constructor receives 3 parameters String name, int id, int height.
I am using the setters to check the validation : for example the height should be between 100cm to 250cm, thus I avoid the redundant instead of checking inside the constructor, but i need to use a while loop in the driver class to keep asking for the height again and again till the user enter a valid data ..
the problem is: How can I specify that the problem was in the height not in the name ..
setHeight(int height){
if(height>=100 && height<=250){
this.height=height;
}
}
the constructor will call this method to set the height and check the validation, but if it is not valid I need the constructor to return something to the user to specify that the app accepted the name but there is a problem in the height .
should I use a static boolean variable for each parameter to see which is not valid or there exist an easier way for it ?