🌙 DARK

Java program to implement Single Inheritance

    1) Single inheritance

Write a Java program to implement Single Inheritance.

[Note: Strictly adhere to the object oriented specifications given as a part of the problem statement. Use the same class names and member variable names.
Follow the naming conventions mentioned for getters/setters
] 


Consider a class named Person with the following private data members.
                           
Data Type    Data Member   
Stringname
StringdateOfBirth
Stringgender
StringmobileNumber
StringbloodGroup

Include appropriate getters and setters.

Consider a class named Donor which extends Person class with the following private data members.
 
Data Type    Data Member   
StringbloodBankName
StringdonorType
StringdonationDate

Include appropriate getters and setters.

The class Donor should have the following method
 
MethodDescription
public void displayDonationDetails( )This method displays the donation details.
Display the statement ‘Donation Details :’ inside this method


Consider another class Main and write the main method to test the above class.

In the main( ) method, read the person and donor details from the user and call the displayDonationDetails( ) method.


[Note: The date format should be “dd-MM-yyyy”]

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 text in bold corresponds to input and the rest corresponds to output.


Sample Input and Output 1:

 
Enter the name :
Justin
Enter Date of Birth :
11-01-1995
Enter Gender :
Male
Enter Mobile Number :
9994910354
Enter Blood Group :
B+ve
Enter Blood Bank Name :
Blood Assurance
Enter Donor Type :
Whole Blood
Enter Donation Date :
09-07-2017
Donation Details :
Name : Justin
Date Of Birth : 11-01-1995
Gender : Male
Mobile Number : 9994910354
Blood Group : B+ve
Blood Bank Name : Blood Assurance
Donor Type : Whole Blood
Donation Date : 09-07-2017



Sample Input and Output 2:
 
Enter the name :
Steffie
Enter Date of Birth :
12-01-1996
Enter Gender :
Female
Enter Mobile Number :
8868875432
Enter Blood Group :
O+ve
Enter Blood Bank Name :
Edward Blood Bank
Enter Donor Type :
Whole Blood
Enter Donation Date :
21-12-2016
Donation Details :
Name : Steffie
Date Of Birth : 12-01-1996
Gender : Female
Mobile Number : 8868875432
Blood Group : O+ve
Blood Bank Name : Edward Blood Bank
Donor Type : Whole Blood
Donation Date : 21-12-2016

 

PROGRAMS: 

CLASS 1: 

class Person{

private String name;
private String dateOfBirth;
private String gender;
private String mobileNumber;
private String bloodGroup;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDateOfBirth() {
return dateOfBirth;
}
public void setDateOfBirth(String dateOfBirth) {
this.dateOfBirth = dateOfBirth;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getMobileNumber() {
return mobileNumber;
}
public void setMobileNumber(String mobileNumber) {
this.mobileNumber = mobileNumber;
}
public String getBloodGroup() {
return bloodGroup;
}
public void setBloodGroup(String bloodGroup) {
this.bloodGroup = bloodGroup;
}
}



CLASS 2: 


class Donor extends Person {
    
        private String bloodBankName;
        private String donorType;
        private String donationDate;
public String getBloodBankName() {
return bloodBankName;
}
public void setBloodBankName(String bloodBankName) {
this.bloodBankName = bloodBankName;
}
public String getDonorType() {
return donorType;
}
public void setDonorType(String donorType) {
this.donorType = donorType;
}
public String getDonationDate() {
return donationDate;
}
public void setDonationDate(String donationDate) {
this.donationDate = donationDate;
}
        
public void displayDonationDetails() {
System.out.println("Donation Details :");
System.out.println("Name :"+getName());
System.out.println("Date Of Birth : "+getDateOfBirth());
System.out.println("Gender : "+getGender());
System.out.println("Mobile Number : "+getMobileNumber());
System.out.println("Blood Group : "+getBloodGroup());
System.out.println("Blood Bank Name : "+getBloodBankName());
System.out.println("Donor Type : "+getDonorType());
System.out.println("Donation Date : "+getDonationDate());
}
}





CLASS 3: 



import java.io.*;
import java.util.Scanner;
public class Main { 
    public static void main(String[] args){ 
         Donor donor=new Donor();
       Scanner sc=new Scanner(System.in).useDelimiter("\n");
       System.out.println("Enter the name :");
       String name=sc.next();
       System.out.println("Enter Date of Birth :");
       String dateOfBirth=sc.next();
       System.out.println("Enter Gender :");
       String gender=sc.next();
       System.out.println("Enter Mobile Number :");
       String mobileNumber=sc.next();
       System.out.println("Enter Blood Group :");
       String bloodGroup=sc.next();
       System.out.println("Enter Blood Bank Name :");
       
       String bloodBankName=sc.next();
       System.out.println("Enter Donor Type :");
       
       String donorType=sc.next();
       System.out.println("Enter Donation Date :");
       String donationDate=sc.next();
      
       donor.setName(name);
       donor.setDateOfBirth(dateOfBirth);
       donor.setGender(gender);
       donor.setMobileNumber(mobileNumber);
       donor.setBloodGroup(bloodGroup);
       donor.setBloodBankName(bloodBankName);
       
       donor.setDonorType(donorType);
       donor.setDonationDate(donationDate);
       donor.displayDonationDetails();
    } 
}



OUTPUT:

Donation Details :
Name : Steffie
Date Of Birth : 12-01-1996
Gender : Female
Mobile Number : 8868875432
Blood Group : O+ve
Blood Bank Name : Edward Blood Bank
Donor Type : Whole Blood
Donation Date : 21-12-2016

 







MOTIVATION :

    “Time is the most valuable thing a man can spend.”


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




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