Answer to Question #195858 in Java | JSP | JSF for Hamza baig

Question #195858

Create a class named Person , which contains . A function named print ( ) Two data fields i.e. person Name and age A class named Patient inherits Person class , which contains Two data fields i.e. disease Type and recommended Medicine Overridden function print ( ) to display all details relevant to a patient A class named Medicare Patient inherited from class Patient , which holds A data field representing the name of the hospital A data filed representing the name of the ward A data field representing room number Overridden function print ( ) isplay all details relevant to . . In the main function , create instances of derived classes to access respective print ( ) function using dynamic binding .


1
Expert's answer
2021-05-21T10:53:03-0400
public class Person {
	private String personName;
	private int age;


	public Person(String personName, int age) {
		this.personName = personName;
		this.age = age;
	}


	public String getPersonName() {
		return personName;
	}


	public void setPersonName(String personName) {
		this.personName = personName;
	}


	public int getAge() {
		return age;
	}


	public void setAge(int age) {
		this.age = age;
	}


	public String print() {
		return "Person [personName=" + personName + ", age=" + age + "]";
	}
}

public class Patient extends Person {


	private String diseaseType;
	private String recommendedMedicine;


	public Patient(String personName, int age, String diseaseType, String recommendedMedicine) {
		super(personName, age);
		this.diseaseType = diseaseType;
		this.recommendedMedicine = recommendedMedicine;
	}


	public String getDiseaseType() {
		return diseaseType;
	}


	public void setDiseaseType(String diseaseType) {
		this.diseaseType = diseaseType;
	}


	public String getRecommendedMedicine() {
		return recommendedMedicine;
	}


	public void setRecommendedMedicine(String recommendedMedicine) {
		this.recommendedMedicine = recommendedMedicine;
	}


	@Override
	public String print() {
		return "Patient [diseaseType=" + diseaseType + ", recommendedMedicine=" + recommendedMedicine + "]";
	}
}



public class MedicarePatient extends Patient {
	private String nameOfTheHospital;
	private String nameOfTheWard;
	private int roomNumber;
	
	public MedicarePatient(String personName, int age, String diseaseType, String recommendedMedicine,
			String nameOfTheHospital, String nameOfTheWard, int roomNumber) {
		super(personName, age, diseaseType, recommendedMedicine);
		this.nameOfTheHospital = nameOfTheHospital;
		this.nameOfTheWard = nameOfTheWard;
		this.roomNumber = roomNumber;
	}


	public String getNameOfTheHospital() {
		return nameOfTheHospital;
	}


	public void setNameOfTheHospital(String nameOfTheHospital) {
		this.nameOfTheHospital = nameOfTheHospital;
	}


	public String getNameOfTheWard() {
		return nameOfTheWard;
	}


	public void setNameOfTheWard(String nameOfTheWard) {
		this.nameOfTheWard = nameOfTheWard;
	}


	public int getRoomNumber() {
		return roomNumber;
	}


	public void setRoomNumber(int roomNumber) {
		this.roomNumber = roomNumber;
	}


	@Override
	public String print() {
		return "MedicarePatient [nameOfTheHospital=" + nameOfTheHospital + ", nameOfTheWard=" + nameOfTheWard
				+ ", roomNumber=" + roomNumber + "]";
	}
}

public class Demo {
    public static void main(String[] args) {
		Person person = new Person("Piter", 25);
		System.out.println(person.print());
		Person personTwo = new Patient("Piter", 25, "apendicites", "surgery");
		System.out.println(personTwo.print());
		Person personThree = new MedicarePatient("Piter", 25, "apendicities", "surgery", "NYC city hospital",
				"General surgery", 15);
		System.out.println(personThree.print());
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS