SUNDAY, 12 JULY 2026
Guide For School logo Guide For SchoolStudy Guide For Students On Java Programming
Physics | Chemistry | Mathematics
ICSE | ISC | CBSE
Guide For School logo Guide For SchoolICSE and ISC Resources

[Question 1] ISC 2019 Computer Practical Paper Solved – Future Date

20 December 2020

ISC 2019 future date program solved with algorithm, explanation, Java program and Python code.

Click here to download the complete ISC 2019 Computer Science Paper 2 (Practical).


Question:

Design a program to accept a day number (between 1 and 366), year (in 4 digits) from the user to generate and display the corresponding date. Also, accept ‘N’ (1 <= N <= 100) from the user to compute and display the future date corresponding to ‘N’ days after the generated date. Display an error message if the value of the day number, year and N are not within the limit or not according to the condition specified.

Test your program with the following data and some random data:

Example 1

INPUT:
DAY NUMBER: 255
YEAR: 2018
DATE AFTER (N DAYS): 22

OUTPUT:
DATE: 12 TH SEPTEMBER, 2018
DATE AFTER 22 DAYS: 4 TH OCTOBER, 2018

Example 2

INPUT:
DAY NUMBER: 360
YEAR: 2018
DATE AFTER (N DAYS): 45

OUTPUT:
DATE: 26 TH DECEMBER, 2018
DATE AFTER 45 DAYS: 9 TH FEBRUARY, 2019

Example 3

INPUT:
DAY NUMBER: 500
YEAR: 2018
DATE AFTER (N DAYS): 33

OUTPUT:
DAY NUMBER OUT OF RANGE.

Example 4

INPUT:
DAY NUMBER: 150
YEAR: 2018
DATE AFTER (N DAYS): 330

OUTPUT:
DATE AFTER (N DAYS) OUT OF RANGE.


Algorithm:

Step 1: Start.

Step 2: Input the day number and the year.

Step 3: Check whether the year is a leap year and decide whether it has 365 or 366 days.

Step 4: If the day number is outside the valid range, display DAY NUMBER OUT OF RANGE and stop.

Step 5: If the year is not a four-digit year, display YEAR OUT OF RANGE and stop.

Step 6: Input the number of days after.

Step 7: If this value is outside the range 1 to 100, display DATE AFTER (N DAYS) OUT OF RANGE and stop.

Step 8: Convert the original day number into day, month and year format.

Step 9: Add the given number of days, adjust the year if the result crosses the end of the year, and display the future date.

Step 10: Stop.

Explanation:

The program works with a day number instead of a normal date. For example, in a non-leap year, day number 1 is 1 January and day number 365 is 31 December. The first important step is to check whether the entered year is a leap year, because February has 29 days in a leap year and the maximum day number becomes 366. The program uses a month-days array to store the number of days in each month and changes February to 29 when required.

To display a date from a day number, the program repeatedly subtracts the number of days in each month until the remaining value fits in the current month. That remaining value is the day of the month. The same method is used after adding the required number of future days. If the new day number becomes greater than the total days in the year, the program subtracts the year's maximum days and increases the year by one. The suffix function adds ST, ND, RD or TH to make the date format match the ISC output style.


A useful trace is day number 360 in the year 2019. Since 2019 is not a leap year, the year has 365 days. Subtracting month lengths from 360 leaves 26 in December, so the current date is 26 December 2019. Adding 80 gives 440, which crosses 365. The program subtracts 365, moves to 2020, and then converts day number 75 of 2020 into 15 March 2020. This shows why leap-year checking and year rollover must be handled before displaying the final date.

Programming Code:

Java
/**
  * The class ISC2019_Q1 inputs a day number, year and number of days after
  * and prints the current date and the future date
  * @author : www.guideforschool.com 
  * @Program Type : BlueJ Program - Java
  * @Question Year : ISC Practical 2019 Question 1 
  */
import java.util.*;
class ISC2019_Q1
{
    int isLeap(int y) //function to check for leap year and return max days
    {
        if((y%400 == 0) || (y%100 != 0 && y%4 == 0))
            return 366;
        else
            return 365;
    }

    String postfix(int n) //function to find postfix of the number
    {
        int r = n%10;
        if(r == 1 && n != 11)
            return "ST";
        else if(r == 2 && n != 12)
            return "ND";
        else if(r == 3 && n != 13)
            return "RD";
        else
            return "TH";
    }

    void findDate(int d, int y) //function to find the date from day number
    {
        int D[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        String MO[] = {"", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY",
                          "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"};
        if(isLeap(y)==366)
        {
            D[2] = 29;
        }
        int m = 1;
        while(d > D[m])
        {
            d = d - D[m];
            m++;
        }
        System.out.println(d+postfix(d)+" "+MO[m]+", "+y);
    }
    
    void future(int d, int y, int n) //function to find future date
    {
        int max = isLeap(y);
        d = d + n;
        if(d>max)
        {
            d = d - max;
            y++; 
        }
        findDate(d,y); 
    }
    
    public static void main(String args[])
    {
        ISC2019_Q1 ob = new ISC2019_Q1();
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the day number : ");
        int day = sc.nextInt();
        System.out.print("Enter the year : ");
        int year = sc.nextInt();
        int max = ob.isLeap(year);
        if(day > max)
        {
            System.out.println("DAY NUMBER OUT OF RANGE");
        }
        else if(year<1000 || year>9999)
        {
            System.out.println("YEAR OUT OF RANGE");
        }
        else
        {
            System.out.print("Enter the number of days after : ");
            int n = sc.nextInt();
            if(n<1 || n>100)
            {
                System.out.println("DATE AFTER (N DAYS) OUT OF RANGE");
            }
            else
            {
                System.out.print("DATE :\t\t\t");
                ob.findDate(day,year);
                System.out.print("DATE AFTER "+n+" DAYS :\t");
                ob.future(day,year,n);
            }
        }
    }       
}

Equivalent Python Program:

Python
def max_days(year):
    if year % 400 == 0 or (year % 100 != 0 and year % 4 == 0):
        return 366
    return 365


def suffix(day):
    if day % 100 in (11, 12, 13):
        return "TH"
    if day % 10 == 1:
        return "ST"
    if day % 10 == 2:
        return "ND"
    if day % 10 == 3:
        return "RD"
    return "TH"


def print_date(day_number, year):
    days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    months = ["", "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"]

    if max_days(year) == 366:
        days[2] = 29

    month = 1
    while day_number > days[month]:
        day_number -= days[month]
        month += 1

    print(str(day_number) + suffix(day_number) + " " + months[month] + ", " + str(year))


def future_date(day_number, year, after_days):
    day_number += after_days
    if day_number > max_days(year):
        day_number -= max_days(year)
        year += 1
    print_date(day_number, year)


day = int(input("Enter the day number : "))
year = int(input("Enter the year : "))

if day > max_days(year):
    print("DAY NUMBER OUT OF RANGE")
elif year < 1000 or year > 9999:
    print("YEAR OUT OF RANGE")
else:
    after_days = int(input("Enter the number of days after : "))
    if after_days < 1 or after_days > 100:
        print("DATE AFTER (N DAYS) OUT OF RANGE")
    else:
        print("DATE :			", end="")
        print_date(day, year)
        print("DATE AFTER " + str(after_days) + " DAYS :	", end="")
        future_date(day, year, after_days)

Output:

Enter the day number : 360
Enter the year : 2019
Enter the number of days after : 80
DATE : 26TH DECEMBER, 2019
DATE AFTER 80 DAYS : 15TH MARCH, 2020

Leave a Reply

Your email address will not be published. Comments are reviewed before appearing publicly.

Send a comment or correction

Study smarter

Everything you need for ICSE and ISC Computer

Programs, revision notes, solved papers and practical guidance—organized for quick study.

Browse all resources →