In order to write good code, you need to handle the case when the user gives bad input. That never happens, right?! Think of an interface on a website that asks for a phone number. In the US, we have several ways to represent a phone number. A few examples below:
1-515-867-5309
515-867-5309
(515)867-5309
If the site lets you type in alphanumeric characters {A-Z,a-z,0-9} there can be errors if that information is being save to a database and a specific format is expect. You could write code to check the format and fix it, that adds complexity. A simpler approach you may have seen is when the user is only allowed to enter numbers and the parenthesis and hyphens are provided.
Look at the program you finished. test it with bad input. What do you see? Complete the journal below with the error you see. You will learn to handle this soon! Once you learn how to handle bad input (invalid input) you should always validate input.
Run your previous and output assignment. Test 3 types of bad input. Call the method 3 separate times with the following
1. Non-numeric characters
2. Alpha characters
3. Negative numbers