Question: please do NOT use split or array . code should be written in java Problem: The purpose of this assignment is to gain experience solving
please do NOT use split or array . code should be written in java
Problem:
The purpose of this assignment is to gain experience solving user input problems by using exception handling in your Java code.
Write a program that reads a string from the keyboard and tests whether it contains a valid date. Display the date as described below if it is valid, otherwise display a message as described below. The input date should have the format mm/dd/yyyy, where mm and dd can be one or two digits.
Here are the input errors (exceptions) that your program should detect and deal with:
Receive the input from the user (give an example of the format you are expecting the user to use when entering the date) and check for the following:
missing one of parts (that is the month or the day or the year is missing. Check this by checking the number of slashes (/)), eg mm/dd is invalid
mm or dd or yyyy is not numeric
month not between 1 and 12
day is not in the right range (this depends on the month)
year isnt 2000 or higher
If the user gives you invalid input, start the whole process again by asking the user for a valid date. Keep prompting the user until you get a valid date. A while (!valid) loop would work well here.
If the date is valid, then output a message with a copy of the input date values indicating it is a valid date.
Bonus Mark: One of the checks should be for leap years. February has 28 days except for leap years when it has 29. A leap year (for the 2000s) is any year divisible by 4.
Notes:
String class methods (indexOf method) can be used to find the slashes (/). Strings can be converted to integers by using the Integer.parseInt( ) method.
Be sure that the output that you submit shows that your program has tested ALL the different types of errors that can occur.
Write a dateException class that is called if the input date is not valid, watch out for the NumberFormatException (this is a built in Java exception class) if the input string has the correct format, ie mm/dd/yyyy, then determine if the input consists of numbers only (ie, no non-numeric characters other than /). The easiest way to do this is to use the parseInt method from the Integer class, ie Integer.parseInt(mm) or parseInt(dd). parseInt( ) will throw a NumberFormatException if mm or dd cant be converted to an integer
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
