Q3) Write a program that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format dd/mm/yyyy. A valid month value mm must be from 1 to 12 (January is 1). The day value dd must be from 1 to a value that is appropriate for the given month. September, April, June, and November each have 30 days. February has 28 days except for leap years when it has 29. The remaining months all have 31 days each. A leap year is any year that is divisible by 4 but not divisible by 100 unless it is also divisible by 400. Sample Input#1: Please enter a date to be checked: 05/04/2021 Sample Output#1: Your date was 05:04:2021 It is a valid date. Sample Input #2: Please enter a date to be checked: 32/03/2021 Sample Output #2: Your date was 32:03:2021 It isn’t a valid date.The reason it is invalid:The day value is greater than 31 in a month with just 31 days. Sample Input #3: Please enter a date to be checked: 30/02/2020 Sample Output #3: Your date was 30:02:2020. It isn’t a valid date.The reason it is invalid:The day value is greater than 29 in February in a leap year. Sample Input #4: Please enter a date to be checked: 29/02/2019 Sample Output #4: Your date was 29:02:2019. It isn’t a valid date.The reason it is invalid:The day value is greater than 28 in February in a non- leap year. Note: you should upload a java project file, otherwise will not be accepted.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images