Build a java program to validate a date in the future as entered by the user at the keyboard as three separate integer values:
mm
dd
yyy
Acceptable data criteria:
1. mm: month in range of 1-12
2. dd: day in range of 1-30 for April, June. September, & Nov. / 1-31 January, March, May, July, August, October, & December. Only accept 1-28 for February at this point.
3. yyy: current year (as long as the month and day have yet to occur), or any future year.
Note: Make sure your prompts and displayed outcomes will be to the screen and should be user friendly, including directions that the date to choose is in the future. Input is from the keyboard.
here i have create validate_date class and implement the program
code for validate_date:
package validate_date;
import java.util.Scanner;
public class Validate_date
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);//scanner object for user
input
int dd;
int mm;
int yyy;//three inputs
System.out.println("Enter Day: ");
dd = sc.nextInt();
System.out.println("Enter Month");
mm = sc.nextInt();
System.out.println("Enter Year");
yyy = sc.nextInt();//three user input and store value in mm dd and
yyy as per your requirment
System.out.print(+dd);
System.out.print("/");// date separator
System.out.print(+mm);
System.out.print("/");// date separator
System.out.print(+yyy);
boolean Date_True = true;//boolean variable Date_True
if(mm > 12)
{
Date_True = false;//false if month is invalid
}
else if (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm
== 10 || mm == 12)//check month for 31 date
{
if (dd <= 31)
{
Date_True = true;
}
else if (dd >= 31)
{
Date_True = false;
}
}
else if (mm == 4 || mm == 6 || mm == 9 || mm == 11)//check month
for 30 date
{
if (dd <= 30)
{
Date_True = true;
}
else if (dd >= 30)
{
Date_True = false;
}
}
else if (mm == 2) // month check of February
{
if (yyy % 4 == 0) // check it is Leap year or not for
february
{
if (dd <= 29)
{
Date_True = true;
}
else if (dd >= 29)
{
Date_True = false;
}
}
else if (yyy % 4 != 0)
{
if (dd <= 28)
{
Date_True = true;
}
else if (dd >= 28)
{
Date_True = false;
}
}
}
if(Date_True)//check date is valid or invalid
{
System.out.println("\n Valid Date");
}
if(!Date_True)
{
System.out.println("\n Invalid Date");
}
}
}
Output
Thank you if you have any query regarding above answer please ask me in comment box.
if you like my work appreciate with thumbs up.
Thank You.
Build a java program to validate a date in the future as entered by the user...
Write a program that prompts the user to enter the date in mm/dd/yyyy format. The program should use a single input statement to accept the date, storing each piece of the date into an appropriate variable. Demonstrate that the input was obtained correctly by outputting the month, day, and year to the screen. Sample output: Enter (date (mm/dd/yyyy): 02/08/2011 Month entered: 2 Day entered: 8 Year entered: 2011 Challenge: Although the user entered 02, C++ drops the 0 as insignificant...
I need this in Java, please! The ISO 8601 Standard date format for Information Interchange indicates that a date be written as such: yyyy-MM-dd (eg. 2012-07-02, 1999-12-05, 1998 -01-27 ) where yyyy represents the four digit year MM represents a two digit numerical month dd represents a two digit numerical day Chinese date format is specified as: yyyy-M-d Macedonean date format is specified as: d.M.yyyy where yyyy represents the four digit year M represents a one or two digit numerical...
C Program Question 1: Write a program that reads a date 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: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid...
C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...
Question 1: Write a program in C that reads a date 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: mm/dd/yyyy Note that there is no space in the above format. A date in this format must be entered in one line. A valid...
Write a C++ program that determines the user's age after the user enters both the current date and hisher birthdate as 3 integers: yyyy mm dd Define a class which is named DateType and will be used to declare 2 objects: "birthday" and "today". The class will have a function "output" which will display the date in conventional form (like it is above next to Date Assigned: Month dd, yyyy and it will have a second function named “input”...
Language: Java The date June 10 1960 is special because when it is written in the form: month times day it will equal to the year (last two digits only). For example, 6 (for June) times 10 (day 10) equals 60 (the last two digits of year 1960). Write program to prompt user to enter month as an integer, day as an integer and a 2-digits integer for the year. No need to validate these input. Only test for being...
JAVA programing Question 1 (Date Class): 5 Points Create a class Date with the day, month and year fields (attributes). Provide constructors that: A constructor that takes three input arguments to initialize the day, month and year fields. Note 1: Make sure that the initialization values for the day, month and year fields are valid where the day must be between 1 and 31 inclusive, the month between 1 and 12 inclusive and the year a positive number. Note 2:...
Write a program that prompts the user to enter a person's birth date in numeric form (e.g. 8-27-1980) and outputs the date of birth in the format of month day, year (e.g. August 27, 1980). Your program must work for three types of exceptions - invalid day, invalid month and invalid year (year must be between 1915 and 2015). Make these as class driven exceptions. Use one try-catch block with separate catches for the exception classes to handle errors for...
Write a Java console application 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 mm/dd/yyyy. A valid month value mm must be from 1 to 12 (January is 1). You can use: String monthPart = inputDate.substring(0, 2); int month =...