Date Validity Program ISC Computer Science 2011 Practical

Design a program which accepts your date of birth in dd mm yyyy format.

Check whether the date entered is valid or not. If it is valid, display "VALID DATE" and also compute and display the day number of the year for the date of birth.

If it is invalid, display "INVALID DATE" and then terminate the program.

Test your program for the given sample data and some random data.

Example 1:
INPUT:
Enter your date of birth in dd mm yyyy format:
05 01 2010
OUTPUT:
VALID DATE
DAY NUMBER: 5

Example 2:
INPUT:
Enter your date of birth in dd mm yyyy format:
03 04 2010
OUTPUT: VALID DATE
DAY NUMBER: 93

Example 3:
INPUT:
Enter your date of birth in dd mm yyyy format:
34 06 2010
OUTPUT:
INVALID DATE

import java.util.Scanner;
class MyDate{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.println("Enter your date of birth in dd mm yyyy format: ");
        int dt = Integer.parseInt(in.nextLine());
        int mt = Integer.parseInt(in.nextLine());
        int yr = Integer.parseInt(in.nextLine());
        int md[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if((yr % 4 == 0 && yr % 100 != 0) || yr % 400 == 0)
            md[2] = 29;
        if(mt <= 0 || mt > 12 || dt <= 0 || dt > md[mt]){
            System.out.println("INVALID DATE");
            return;
        }
        System.out.println("VALID DATE");
        int sum = dt;
        for(int i = 1; i < mt; i++)
            sum += md[i];
        System.out.println("DAY NUMBER: " + sum);
    }
}

Comments

Popular posts from this blog

Encrypt Program ISC Specimen 2023 Theory

No Repeat Program ISC Computer Science 2022 Semester 2 Theory

Bank Inheritance Program ISC Specimen 2023 Theory