Inheritance - Flight
Write a program to implement
single inheritance for the given scenario.
[Note: Strictly adhere to the object-oriented specifications
given as a part of the problem statement. Follow the naming conventions as
mentioned. Create separate classes in separate files.]
Create a class Flight with the following protected
variables:
Data Type |
Variable Name |
String |
clientName |
String |
idProof |
Date |
flightschedule
|
Include appropriate getters
and setters method in the Flight class.
Define a constructor with parameters passed in the same order as
declared in the class. Here idProof may be PAN Card, Voter's ID, Driving
License, Aadhar Card
Create a class InternationalFlight (which should
inherit Flight) with the following
private variables:
Data Type |
Variable Name |
String |
passportNumber
|
String |
natureOfVisit
|
Include getters and setters
method in the InternationalFlight class.
Define a constructor by
invoking the base class constructor with parameters passed in the same order as
declared in the class.
Include the following methods
in the InternationalFlight class
Method |
Description |
void
displayFlightDetails() |
This method should display all the details of
the flight like clientName, idProof, flightschedule,
passportNumber, natureOfVisit. |
Consider the driver class Main. In the main( ) method, read
inputs, create a reference to the parent class and assign the child instance to
it and call the appropriate method in it.
Note:
The format for parsing date
should be “dd/MM/yyyy”
[All text in bold corresponds to input and the rest corresponds to
output.]
Sample input and output:
Enter the client name
Irene
Enter the id proof
PAN Card
Enter the flight schedule
01/01/2017
Enter the passport number
AU7634905
Enter the nature of visit
Higher Education
Flight Details :
Name : Irene
ID Proof : PAN Card
Flight Schedule : 01/01/2017
Passport Number : AU7634905
Flight Schedule : Higher
Education
Problem Requirements:
Java
Keyword |
Min Count |
Max Count |
super |
1 |
- |
package Mr_Programmer;
import java.util.*;
public class Flight{
private String clientName;
private String idProof;
private Date flightschedule;
public
Flight(String clientName, String idProof, Date flightschedule) {
this.clientName=clientName;
this.idProof=idProof;
this.flightschedule=flightschedule;
}
public String
getClientName() {
return clientName;
}
public void
setClientName(String clientName) {
this.clientName = clientName;
}
public String
getIdProof() {
return idProof;
}
public void
setIdProof(String idProof) {
this.idProof = idProof;
}
public Date
getFlightschedule() {
return flightschedule;
}
public void
setFlightschedule(Date flightschedule) {
this.flightschedule = flightschedule;
}
}
package Mr_Programmer;
import
java.util.Date;
public class
InternationalFlight extends Flight {
private String passportNumber;
private String natureOfVisit;
public String
getPassportNumber() {
return passportNumber;
}
public void
setPassportNumber(String passportNumber) {
this.passportNumber = passportNumber;
}
public String
getNatureOfVisit() {
return natureOfVisit;
}
public void
setNatureOfVisit(String natureOfVisit) {
this.natureOfVisit = natureOfVisit;
}
public
InternationalFlight (String clientName,String idProof, Date flightschedule,String passportNumber,String natureOfVisit) {
super(clientName,idProof,flightschedule);
this.passportNumber=passportNumber;
this.natureOfVisit=natureOfVisit;
}
public void
displayFlightDetails() {
System.out.println("Flight
Details :");
System.out.println("Name
:"+getClientName());
System.out.println("ID
Proof :"+getIdProof());
System.out.println("Flight
Schedule :"+getFlightschedule());
System.out.println("Passport
Number :"+getPassportNumber());
System.out.println("nature
of visit :"+getNatureOfVisit());
}
}
package Mr_Programmer89;
import
java.text.ParseException;
import
java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public class Inheritance_Flight_main
{
public static void main (String args[]) throws
ParseException {
Scanner sc = new Scanner (System.in);
System.out.println("Enter the
client name");
String clientName=sc.nextLine();
System.out.println("Enter the id
proof");
String idProof=sc.nextLine();
System.out.println("Enter the flight
schedule");
String d1=sc.nextLine();
SimpleDateFormat formatter = new
SimpleDateFormat("dd/MM/yyyy");
Date
flightschedule=formatter.parse(d1);
System.out.println("Enter the
passport number");
String passportNumber = sc.nextLine();
System.out.println("Enter the
nature of visit");
String natureOfVisit = sc.nextLine();
InternationalFlight f1 =new
InternationalFlight(clientName,idProof,flightschedule,passportNumber,natureOfVisit);
f1.displayFlightDetails();
}
}
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