Practical PapersISCClass 12Computer Science

ISC Practical 2027: Ticket Date Analyzer (Day Number, Gaps and Fare Type) – Algorithm and Java Program

Fully solved ISC Computer Science Practical 2027 date question: convert booking, travel and return dates to day numbers of the year, validate their order, find the booking gap and trip duration, and decide the fare type.

7 min read
ISC Practical 2027: Ticket Date Analyzer (Day Number, Gaps and Fare Type) – Algorithm and Java Program

This is Question 3 of Sample Paper 3 from the specimen questions CISCE has released for the ISC Year 2027 Computer Science Practical (Paper 2). The concept area is Date concept. Below you will find the question, a plain-language explanation of the logic, an exam-ready algorithm, a fully documented Java program, the real output for every sample input, and tips for scoring the full 15 marks.

Every program on this page was compiled with JDK 21 and run on CISCE’s sample inputs, plus extra boundary inputs of the kind a visiting examiner will try.

The question

An airline records three dates for a passenger: Booking Date, Travel Date and Return Date. Each date is entered as day, month and year. Assume that all dates are valid, are in the same year, and that the year is between 2024 and 2030. Design a class TicketDateAnalyzer to process these dates.

  1. Find and display the day number of the year for each date. For example, 15 February = Day 46.
  2. The travel date must be after the booking date; otherwise display "Invalid Booking" and stop. The return date must be after the travel date; otherwise display "Invalid Return" and stop.
  3. Find and display the Booking Gap (days between booking and travel) and the Trip Duration (days between travel and return).
  4. Fare type: if the booking gap is at least twice the trip duration, display "Advance Saver". If the trip duration is at least twice the booking gap, display "Long-Stay Premium". Otherwise display "Standard Fare".

CISCE gives 3 examples with this question. Each one is shown with its output in the Output section below, so you can check your own program against it.

Understanding the problem

A date concept question. The key idea is the day number: once each date becomes a number from 1 to 366, comparing dates and finding gaps is ordinary subtraction.

  • Day number = days in all earlier months + the day. Keep the month lengths in an array {31, 28, 31, …}.
  • Leap years matter. The range 2024–2030 contains two leap years (2024 and 2028). Add 1 for any date after February in a leap year. Rule: divisible by 4 and not by 100, or divisible by 400.
  • "After" means strictly later. A travel date equal to the booking date is an invalid booking.
  • Print the day numbers before the error message. Examples 2 and 3 show all three day numbers and then INVALID BOOKING or INVALID RETURN.
Timeline showing booking, travel and return day numbers with the booking gap and trip duration
Question 9: worked example

Algorithm [3 marks]

Write the algorithm in the planning session, in numbered steps like these. It must match your program exactly.

  1. Start.
  2. Input the booking, travel and return dates as day, month and year.
  3. Define dayNumber(d, m) = d + the sum of the month lengths for months 1 to m − 1, plus 1 if m > 2 and the year is a leap year.
  4. Compute b, t and r, the day numbers of the three dates, and print them.
  5. If t ≤ b, print "INVALID BOOKING" and stop.
  6. If r ≤ t, print "INVALID RETURN" and stop.
  7. gap = t − b and trip = r − t. Print both.
  8. If gap ≥ 2 × trip, print "Advance Saver"; else if trip ≥ 2 × gap, print "Long-Stay Premium"; otherwise print "Standard Fare".
  9. Stop.

Java program [7 marks]

The program uses a class with separate methods for each task and comments that explain every data member and the special logic. That is what the 2 documentation marks are for.

TicketDateAnalyzer.java
import java.util.Scanner;

/**
 * ISC Practical 2027 - Sample Paper 3, Question 3
 * Converts booking, travel and return dates to day numbers, checks their order
 * and decides the fare type.
 */
public class TicketDateAnalyzer
{
    int bd, bm, td, tm, rd, rm;      // day and month of the booking, travel and return dates
    int year;                        // common year of all three dates
    static final int MDAYS[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    boolean isLeap(int y)
    {
        return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
    }

    // day number of the year, for example 15 February = 46
    int dayNumber(int d, int m)
    {
        int n = d;
        for (int i = 0; i < m - 1; i++)
            n += MDAYS[i];
        if (m > 2 && isLeap(year))
            n++;                     // 29 February comes before this date
        return n;
    }

    void accept(Scanner sc)
    {
        System.out.print("Booking Date: ");
        bd = sc.nextInt(); bm = sc.nextInt(); year = sc.nextInt();
        System.out.print("Travel Date: ");
        td = sc.nextInt(); tm = sc.nextInt(); sc.nextInt();
        System.out.print("Return Date: ");
        rd = sc.nextInt(); rm = sc.nextInt(); sc.nextInt();
    }

    void analyse()
    {
        int b = dayNumber(bd, bm);
        int t = dayNumber(td, tm);
        int r = dayNumber(rd, rm);
        System.out.println("Booking Day Number: " + b);
        System.out.println("Travel Day Number: " + t);
        System.out.println("Return Day Number: " + r);
        if (t <= b)
        {
            System.out.println("INVALID BOOKING");
            return;
        }
        if (r <= t)
        {
            System.out.println("INVALID RETURN");
            return;
        }
        int gap = t - b;             // days between booking and travel
        int trip = r - t;            // days between travel and return
        System.out.println("Booking Gap: " + gap + " days");
        System.out.println("Trip Duration: " + trip + " days");
        String fare;
        if (gap >= 2 * trip)
            fare = "Advance Saver";
        else if (trip >= 2 * gap)
            fare = "Long-Stay Premium";
        else
            fare = "Standard Fare";
        System.out.println("Fare Type: " + fare);
    }

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        TicketDateAnalyzer ob = new TicketDateAnalyzer();
        ob.accept(sc);
        ob.analyse();
    }
}

Variable description

Variable description
Name           Type       Purpose
-------------  ---------  -------
bd, bm         int        day and month of the booking date
td, tm         int        day and month of the travel date
rd, rm         int        day and month of the return date
year           int        common year of the three dates
MDAYS[]        int[]      number of days in each month
b, t, r        int        day numbers of the three dates
gap, trip      int        booking gap and trip duration

Output [3 marks]

These are the actual outputs of the program above for every example in the question:

Example 1
INPUT:
Booking Date: 01 01 2026
Travel Date: 25 01 2026
Return Date: 05 02 2026

OUTPUT:
Booking Day Number: 1
Travel Day Number: 25
Return Day Number: 36
Booking Gap: 24 days
Trip Duration: 11 days
Fare Type: Advance Saver
Example 2
INPUT:
Booking Date: 15 04 2026
Travel Date: 10 04 2026
Return Date: 20 04 2026

OUTPUT:
Booking Day Number: 105
Travel Day Number: 100
Return Day Number: 110
INVALID BOOKING
Example 3
INPUT:
Booking Date: 10 05 2026
Travel Date: 20 05 2026
Return Date: 15 05 2026

OUTPUT:
Booking Day Number: 130
Travel Day Number: 140
Return Day Number: 135
INVALID RETURN

Test it on unknown inputs

One of the 3 output marks is for correct output on inputs the examiner chooses, usually boundary cases. Our program handles these correctly:

Leap year, Long-Stay Premium
INPUT:
Booking Date: 20 02 2028
Travel Date: 01 03 2028
Return Date: 25 03 2028

OUTPUT:
Booking Day Number: 51
Travel Day Number: 61
Return Day Number: 85
Booking Gap: 10 days
Trip Duration: 24 days
Fare Type: Long-Stay Premium
Standard Fare
INPUT:
Booking Date: 01 06 2026
Travel Date: 11 06 2026
Return Date: 25 06 2026

OUTPUT:
Booking Day Number: 152
Travel Day Number: 162
Return Day Number: 176
Booking Gap: 10 days
Trip Duration: 14 days
Fare Type: Standard Fare
Same travel and booking date
INPUT:
Booking Date: 05 09 2027
Travel Date: 05 09 2027
Return Date: 10 09 2027

OUTPUT:
Booking Day Number: 248
Travel Day Number: 248
Return Day Number: 253
INVALID BOOKING

How to score full marks on this question

Marks distribution for the ISC Computer Science practical: algorithm 3, program 7, hard copy 2, output 3
ISC Paper 2: how the 15 exam marks are divided
  • Write isLeap() and dayNumber() as separate methods. Date questions almost always reuse them, and the examiner sees clean structure.
  • Show a leap-year test (e.g. 01 03 2028 is Day 61, not 60). It is the most likely "unknown input".
  • Read the date as three integers with nextInt(). The question gives the input as "01 01 2026", so there is no need to split a string.
  • Keep the typed program identical to the planned one. Large differences between your planning sheet and the printout cost the 2 hard-copy marks.

Common mistakes to avoid

  • Ignoring leap years: every date after February 2024 or 2028 would be one day off.
  • Using < instead of <= in the order checks, so equal dates pass.
  • Checking the fare conditions in the wrong order. Both can never be true at once for positive values, but the question lists Advance Saver first, so keep that order.

This post is part of our series that solves all 12 specimen questions for the ISC 2027 Computer Science practical, one question a day. Practise writing the algorithm and program on paper in 90 minutes before you type it. That is exactly how the exam works.