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 Type | Variable Name |
String | aircraftName |
String | source |
String | destination |
Include getters/ setters.
Include the following public methods
Prototype for the Parameterized Constructor,
public Aircraft(String aircraftName,String source,String destination)
Include the following method.
Method Name | Description |
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 Type | Variable Name |
Boolean | checkInBeforeTwoHours |
int | noOfKgsAllowed |
Double | additionalFeePerkg |
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 getters/ setters.
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 Name | Description |
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 Type | Variable Name |
Boolean | checkInBeforeTwoHours |
String | pilotPreference |
String | purpose |
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 getters/ setters.
Prototype for the Parameterized Constructor,
public PrivateAircraft(String aircraftName,String source,String destination,Boolean checkInBeforeTwoHours,String pilotPreference ,String purpose )
Include the following method.
Method Name | Description |
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
1
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
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);
}
}
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));
}
}
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);
}
}
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