Airline Ticket Date Analyzer | ISC Computer Science 2027 Practical

An airline records three dates for a passenger: Booking Date, Travel Date, Return Date.

Each date is entered as day, month and year. Assume that all dates are valid, are in the
same year, and the year is between 2024 and 2030.

Design a class TicketDateAnalyzer to process these dates.
a. Find and display the day number of the year for each date.
For example, 15 February = Day 46.
b. Check the dates in this order:
Travel date must be after the booking date. Otherwise, display “Invalid Booking”
and stop. Return date must be after the travel date. Otherwise, display “Invalid Return” and
stop. If both are correct, continue.
c. Calculate the Gaps. Find and display:
Booking Gap – the number of days between the booking date and the travel date.
Trip Duration – the number of days between the travel date and the return date.
d. To find the Fare type, Compare the Booking Gap and Trip Duration:
If Booking Gap is at least twice the Trip Duration display “Advance Saver”
If Trip Duration is at least twice the Booking Gap display “Long-Stay Premium”
Otherwise display “Standard Fare”

Test your program for the following data and some random data:
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

import java.util.Scanner;
class TicketDateAnalyzer{
    int d1, m1, y1;
    int d2, m2, y2;
    int d3, m3, y3;
    int bookingDay;
    int travelDay;
    int returnDay;
    int bookingGap;
    int tripDuration;
    int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    public int dayNumber(int d, int m){
        int sum = d;
        for(int i = 0; i < m - 1; i++)
            sum = sum + days[i];
        return sum;
    }
    public void input(){
        Scanner sc = new Scanner(System.in);
        System.out.print("Booking Date: ");
        d1 = sc.nextInt();
        m1 = sc.nextInt();
        y1 = sc.nextInt();
        if(y1 % 400 == 0 || (y1 % 4 == 0 && y1 % 100 != 0))
            days[1] = 29;
        System.out.print("Travel Date: ");
        d2 = sc.nextInt();
        m2 = sc.nextInt();
        y2 = sc.nextInt();
        System.out.print("Return Date: ");
        d3 = sc.nextInt();
        m3 = sc.nextInt();
        y3 = sc.nextInt();
    }
    public void calculate(){
        bookingDay = dayNumber(d1, m1);
        travelDay = dayNumber(d2, m2);
        returnDay = dayNumber(d3, m3);
        System.out.println("Booking Day Number: " + bookingDay);
        System.out.println("Travel Day Number: " + travelDay);
        System.out.println("Return Day Number: " + returnDay);
        if(travelDay <= bookingDay){
            System.out.println("INVALID BOOKING");
            return;
        }
        if(returnDay <= travelDay){
            System.out.println("INVALID RETURN");
            return;
        }
        bookingGap = travelDay - bookingDay;
        tripDuration = returnDay - travelDay;
        System.out.println("Booking Gap: " + bookingGap + " days");
        System.out.println("Trip Duration: " + tripDuration + " days");
        if(bookingGap >= 2 * tripDuration)
            System.out.println("Fare Type: Advance Saver");
        else if(tripDuration >= 2 * bookingGap)
            System.out.println("Fare Type: Long-Stay Premium");
        else
            System.out.println("Fare Type: Standard Fare");
    }
    public static void main(String args[]){
        TicketDateAnalyzer ob = new TicketDateAnalyzer();
        ob.input();
        ob.calculate();
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *