Hello, I really could use help on an assignment to code a health record program to collect info on a patient that inputs data about themselves (name, birthday, height, weight etc.) then calculates their BMI and displays all the values in the main method. The programming requires it be be in two classes with input data as private variables using constructors to pass the info around and a main method to display all the values. Anything can be put in for String variables like their name, but for a number variable like age must be within a set range, and if the answer isn't in that range, the user will be prompted on loop until it is. Two methods are public, one to read values and the other to display them, and the setter and getter methods and the BMI calculation methods are private.
I only have this so far:
It's been hard to wok with constructors, and trying to work at it, could only code the beginning part of the program. Also the instructor requires students to only use Netbeans though I've only been working with BlueJay up until now. This isn't to rush for an answer from anyone, but any help with the program would very much be appreciated, since its due tonight.
Thank you, the scanner part of the code has been changed, and according to assignment, there should be 8 setters for each instance variable, and each one should validate user input. That's why I thought that the object should be there then check if its correct or not within each method. If that is wrong then that code should be in the readInputs method instead, but I wouldn't know how to send each variable from that method to each method since a method can only return one value.
The code only has one setter for each variable but the setter was coded to take in inputs from the user instead, which I suppose the readInputs method should be taking care of instead. The assignment did explain that each private method did have to validate user data and reject it if it wasn't within a certain range, so that's why the inputs where being scanned in each setter method.
I suspect that you haven't gotten to the point where you can run and test what you have so far. In general, when you develop code you try at all times to have a compilable and runable program. This involves an iterative approach, implement one feature, get it to compile, test it, and only when it is successfully tested do you go on to add the next feature.
You've got a lot of code now that hasn't been tested. Had you tested it as you went along you wouldn't have copied the same errors to many methods. Consider setting this code aside and start over. Implement all the code necessary to compile and test 'firstName' only. Make sure your tests include scenarios that test for invalid inputs, such as an empty String for 'firstName'.
I'm making some assumptions here because your requirements leave room for interpretation, but something like this would be the template for all the things you'll need in order to implement the 'firstName' feature.
Good point. OP: please read this. Give such notifications on every forum involved.
posted 1 hour ago
..I honestly wasn't sure whether or not to come back to this post after working out the code with an instructor and then seeing the new replies come in and with them had figured what was wrong. But, it seemed to be that the program wasn't coded right to the point that it wasn't even using setters and getters properly and couldn't even compile. The constructor was removed, and the final printer scan wasn't needed, but everything else was worked through already, it was just confusion on encapsulation being put together correctly. Also, using one variable at a time to test if the variables and their values passed through and the object to send data is good for debugging and did help.
And about the 'crossposting', I was pressed for time when the topic was put up, and didn't want to wait on one source for an answer when someone else instead could give one on another website. It seemed better than repeatedly refreshing the page on one site while running out of time. I wasn't aware of it being considered bad practice to do..
Overall, the new code works, here's the end result.