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.

Unvalidated 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

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.