Single inheritance

 DONOR.JAVA:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class Donor extends Person{

   
        //Fill your code here
	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());
	}
	
	
	
	
}









PERSON.JAVA:
class Person{

	//Fill your code here	
	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;
	}
	
}










MAIN.JAVA:
import java.io.*;
import java.util.Scanner;
public class Main { 
    public static void main(String[] args){ 
       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 donor=new Donor();
       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();
    } 
}

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.