Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to do a date validation with leap years

843789Mar 14 2010 — edited Mar 15 2010
I'm doing a date validation program in my Java class, and well it's pretty hard (for me that is). I have to be able to type in a date, have it say whether it's a leap year or not, and print out the number of days in the month. It seems pretty straight forward, but I get confused on trying to do the 'if else' statements and even the simplest things like getting the day prompting to work. >< The years I'm doing only goes through 1000 to 1999, so that's why those numbers are there. The program isn't complete, so if anyone could help show me what I'm doing wrong in the areas I'm working on then I'd appreciate it...and I'm still kind of in the basics of Java so if you do hint me with some code then I'd appreciate it if it was stuff that's not too advanced so yea.
 
// ****************************************************************
// Dates.java
//
// Determine whether a 2nd-millenium date entered by the user
// is valid 
// ****************************************************************
import java.util.Scanner;

public class Dates
{
public static void main(String[] args)
{
int month, day, year; //date read in from user
int daysInMonth; //number of days in month read in 
boolean monthValid, yearValid, dayValid; //true if input from user is valid
boolean leapYear; //true if user's year is a leap year

Scanner scan = new Scanner(System.in);

//Get integer month, day, and year from user

System.out.print("Type in the month: " );
		month = scan.nextInt();
System.out.print("Type in the day: " );
		day = scan.nextInt();
System.out.print("Type in the year: " );
		year = scan.nextInt();
	
//Check to see if month is valid

if (month >= 1)
month = month;
else

if (month <= 12)
month = month;
else;


//Check to see if year is valid

if (year >= 1000)
year = year;
else

if (year <= 1999)
year = year;
else;

//Determine whether it's a leap year

//Determine number of days in month

if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)
	System.out.println (Number of days in month is 31);
	
	else (year == 4 || 6 || 9 || 11)
	System.out.println (Number of days in month is 30);
	

//User number of days in month to check to see if day is valid


//Determine whether date is valid and print appropriate message


}
}
// ****************************************************************
// Dates.java
//
// Determine whether a 2nd-millenium date entered by the user
// is valid 
// ****************************************************************
import java.util.Scanner;

public class Dates
{
public static void main(String[] args)
{
int month, day, year; //date read in from user
int daysInMonth; //number of days in month read in 
boolean monthValid, yearValid, dayValid; //true if input from user is valid
boolean leapYear; //true if user's year is a leap year

Scanner scan = new Scanner(System.in);

//Get integer month, day, and year from user

System.out.print("Type in the month: " );
		month = scan.nextInt();
System.out.print("Type in the day: " );
		day = scan.nextInt();
System.out.print("Type in the year: " );
		year = scan.nextInt();
	
//Check to see if month is valid

if (month >= 1)
month = month;
else

if (month <= 12)
month = month;
else;


//Check to see if year is valid

if (year >= 1000)
year = year;
else

if (year <= 1999)
year = year;
else;

//Determine whether it's a leap year

//Determine number of days in month

if (year == 1 || 3 || 5 || 7 || 8 || 10 || 12)
	System.out.println (Number of days in month is 31);
	
	else (year == 4 || 6 || 9 || 11)
	System.out.println (Number of days in month is 30);
	

//User number of days in month to check to see if day is valid


//Determine whether date is valid and print appropriate message


}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 12 2010
Added on Mar 14 2010
5 comments
2,174 views