🌙 DARK

Ticket Booking Java Program

 


Inheritance - Booking Tickets

 

Whether you fly for business or leisure purposes, you can choose either private jets or commercial airlines to get from point A to point B. 

The task is to get the flight details and display them. Write a Java program to Implement this task. 

 

[Strictly adhere to the Object-Oriented Specifications mentioned in the problem. Use the same Class names, attribute names, and method names specified here. Use appropriate naming conventions for getters and setters. Create all classes in separate files.] 

 

Consider a class Aircraft

Include the following protected data members/attributes: 

Data TypeVariable Name 
StringaircraftName 
Stringsource
Stringdestination

Include getterssetters

Include the following public methods

Prototype for the Parameterized Constructor, 

public Aircraft(String aircraftName,String source,String destination) 
 

Include the following method.

Method NameDescription
void display()The return type of this method is void, this method prints the details of the Aircraft

 

Consider a class PublicAircraft that extends Aircraft

Include the following private attributes/data members: 

Data TypeVariable Name 
BooleancheckInBeforeTwoHours
intnoOfKgsAllowed
DoubleadditionalFeePerkg

Here checkInBeforeTwoHours is a Boolean value that says whether the passenger should check-in before two hours or not.

This flag is true in the case of PublicAircraft. 

Include getterssetters

Include the following public methods 

Prototype for the Parameterized Constructor,
public PublicAircraft(String aircraftName,String source,String destination,Boolean checkInBeforeTwoHours ,int noOfKgsAllowed,float additionalFeePerkg) 

Include the following method.

Method NameDescription
void display( )This method prints the details of the booking done for the Public aircraft

 

Consider a class PrivateAircraft that extends Aircraft

Include the following private attributes: 

Data TypeVariable Name 
BooleancheckInBeforeTwoHours
StringpilotPreference
Stringpurpose

Here checkInBeforeTwoHours is a Boolean value that says whether the passenger should check-in before two hours or not.
This flag is false in the case of PrivateAircraft. 

Here, pilot preferences is a string for which the name of the pilot should be given by the passenger according to his preference.

Purpose is a string that indicates the purpose of the flight (Medical,Personal,Cargo)

Include getterssetters.

Prototype for the Parameterized Constructor,
public PrivateAircraft(String aircraftName,String source,String destination,Boolean checkInBeforeTwoHours,String pilotPreference ,String  purpose ) 

 

Include the following method.

Method NameDescription
void display( )This method prints the details of the booking done for the Public aircraft

 

Consider a Main class to test the classes defined above. 

 

The link to download the template code is given below
Code Template

 

Input and Output Format: 
 

Refer sample input and output for formatting specifications. 
All the float values should be displayed up to 2 decimal places.

All text in bold corresponds to input and the rest corresponds to output. 

 

Sample Input Output 1: 
 

Enter the name of the Aircraft 

Jet Airways 

Enter the source 

Kolkata

Enter the destination 

Chennai 

Enter the type of Flight 

1.Public Aircraft

2.Private Aircraft

Is the flight check in before two hours

Yes

Enter the number of kgs allowed per person

15

Enter the additional fee charged for extra baggage per Kg

750.00

Flight Details :

Public Aircraft :

Aircraft Name : Jet Airways 

Source : Kolkata

Destination : Chennai

Flight check in before two hours : Yes

Number of kgs allowed per person : 15

Additional fee charged for extra baggage per Kg : 750.00

 

Sample Input Output 2: 
 

Enter the name of the Aircraft 

Spice Jet 

Enter the source 

Kolkata

Enter the destination 

Chennai 

Enter the type of Flight 

1.Public Aircraft

2.Private Aircraft

2

Is the flight check in before two hours

No

Enter the name of the pilot chose

Rex

Enter the Purpose of your flight 

Medical

Flight Details :

Private Aircraft :

Aircraft Name : Spice Jet 

Source : Kolkata

Destination : Chennai

Flight check in before two hours : No

Pilot chose : Rex

Purpose of the flight : Medical 


@MRProgrammer89 


CREATE CLASS < Aircraft :

public class Aircraft {


    protected String aircraftName,source,destination;

    

    public Aircraft(String aircraftName,String source,String destination) {

        this.aircraftName = aircraftName;

        this.source = source;

        this.destination = destination;

    }

    

    public void displayDetails(){

        System.out.println("Aircraft Name : "+aircraftName);

        System.out.println("Source : "+source);

        System.out.println("Destination : "+destination);

    }

    

}


@MRProgrammer89 


CREATE CLASS < PublicAircraft :

public class PublicAircraft extends Aircraft{


    private boolean checkInBeforeTwoHours;

    private int noOfKgsAllowed;

    private double additionalFeePerkg;

     

    public PublicAircraft(String aircraftName,String source,String destination,Boolean checkInBeforeTwoHours ,int noOfKgsAllowed,float additionalFeePerkg) {

        super(aircraftName,source,destination);

        this.checkInBeforeTwoHours=checkInBeforeTwoHours;

    this.noOfKgsAllowed = noOfKgsAllowed;

        this.additionalFeePerkg=additionalFeePerkg;

}

    

    public void displayDetails(){

        System.out.println("Flight Details :");

        System.out.println("Public Aircraft :");

        super.displayDetails();

        if(checkInBeforeTwoHours)

            System.out.println("Flight check in before two hours : "+"Yes");

        else

            System.out.println("Flight check in before two hours : "+"No");

            

        System.out.println("Number of kgs allowed per person : "+noOfKgsAllowed);

        System.out.println("Additional fee charged for extra baggage per Kg : "+String.format("%.2f",additionalFeePerkg));

   }

}


@MRProgrammer89 


CREATE CLASS < PrivateAircraft :



public class PrivateAircraft extends Aircraft{

    

        private boolean checkInBeforeTwoHours;

        private String     pilotPreference,purpose;

        

public PrivateAircraft(String aircraftName,String source,String destination,Boolean checkInBeforeTwoHours,String pilotPreference ,String  purpose ) {

        

            super(aircraftName,source,destination);

            this.checkInBeforeTwoHours=checkInBeforeTwoHours;

            this.pilotPreference=pilotPreference;

            this.purpose=purpose;

  

}

        

        public void displayDetails(){

            System.out.println("Flight Details :");

            System.out.println("Private Aircraft :");

            super.displayDetails();

            if(checkInBeforeTwoHours)

            System.out.println("Flight check in before two hours : "+"Yes");

        else

            System.out.println("Flight check in before two hours : "+"No");

            

            System.out.println("Pilot chose : "+pilotPreference);

            System.out.println("Purpose of the flight : "+purpose);

        }

}



@MRProgrammer89 


CREATE CLASS < Main :


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

    
    public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the name of the Aircraft");
String aircraftName=br.readLine();
System.out.println("Enter the source");
String source=br.readLine();
System.out.println("Enter the destination");
String destination = br.readLine();
System.out.println("Enter the type of Flight\n1.Public Aircraft\n2.Private Aircraft");
int choice=Integer.parseInt(br.readLine());
if(choice==1)
{
System.out.println("Is the flight check in before two hours");
String ans = br.readLine();
Boolean b1;
if(ans.equals("yes"))
{
  b1=true;
}
else
{
b1=false;
}
System.out.println("Enter the number of kgs allowed per person");
int noOfKgsallowed=Integer.parseInt(br.readLine());
System.out.println("Enter the additional fee charged for extra baggage per Kg");
float additionalFeeperkg=Float.parseFloat(br.readLine());
Aircraft b = new PublicAircraft(aircraftName,source,destination,b1,noOfKgsallowed,additionalFeeperkg);
b.displayDetails();
}
if(choice==2)
{
System.out.println("Is the flight check in before two hours");
Boolean ans = Boolean.parseBoolean(br.readLine());
System.out.println("Enter the name of the pilot chose");
String pilotPreference=br.readLine();
System.out.println("Enter the Purpose of your flight");
String purpose=br.readLine();
Aircraft b = new PrivateAircraft(aircraftName,source,destination,ans,pilotPreference,purpose);
b.displayDetails();
}
}
}

@MRProgrammer89 






MOTIVATION :


    “The way we spend our time defines who we are 


Although we may not see each other as often as we’d like, distance is no match for the bond that we share. Thank you for coming to visit. It was fantastic to catch up.


VISITE MORE BLOGS




THANK YOU....😊


Post a Comment

Thanks for reading the blog. We hope it was useful to you and that you learned something new. Will always be writing on new and interesting topics, so you can visit our website to know the latest updates of our blogs. Thank You!

Previous Post Next Post

Contact Form