[go: up one dir, main page]

0% found this document useful (0 votes)
37 views5 pages

Assigement

The document discusses using object-oriented design principles like inheritance, composition, and polymorphism to model classes for a hospital management system. It proposes: 1. Creating a superclass Person for common attributes of Patient and Doctor classes. 2. The CheckUp class has a composition relationship with Patient, Doctor, and ClinicalTest classes. 3. Patient subclasses like InPatient and OutPatient can extend the Patient class to inherit common attributes.

Uploaded by

Mohammad Junid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views5 pages

Assigement

The document discusses using object-oriented design principles like inheritance, composition, and polymorphism to model classes for a hospital management system. It proposes: 1. Creating a superclass Person for common attributes of Patient and Doctor classes. 2. The CheckUp class has a composition relationship with Patient, Doctor, and ClinicalTest classes. 3. Patient subclasses like InPatient and OutPatient can extend the Patient class to inherit common attributes.

Uploaded by

Mohammad Junid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q2

Id , name , address and contact no are common attribute in the Patient and Doctor

Classes. Hence we can create SuperClass to apply inheritance on them

i.e

public class Person {

private in id;

private String name;

private String address;

private String contact;

setter and getter methods

Q3

In CheckUp Class there are has relation (composition) with Patient Class (patient Object or patient detail
),

With Doctor Class (Doctor Object or doctor detail ) and with Clinical Test Class (Object or detail of clinical
test)

Benefits of using Composition:

 Composition allows the reuse of code.


 i.e we hava Patient Class whenever we required Patient information we can reuse PatientClass

 By using composition, we are flexible enough to replace the implementation of a composed


class with a better and improved version. With the help of polymorphism
 By using composition, we can also change the member objects at run time, to dynamically
change the behavior of your program.
i.e
class Test {
List<String> member;
Public Tese() {
if (someCondition) {

member = new ArrayList<String>();


} else {
member = new LinkedList<String>();
} }}
We can also add more Classes i.e Address Class

Public Class Address {

Private String street1;

Private String street2;

// city , state , zip e.t.c

And then we can use Composition concept by adding Address instance Object in Patient Class and
Doctor Class.

Q 4 in Q 2 we create super class for Patient and doctor and below is code of both classes

Hence doctor and patient extend Person therefore all instance and methods will available for both
classes

Doctor Class

Public Class Doctor extends Person {

Private Date dateOfBirth;

Private Date dataOfHiring;

Private String specialization

setter and getter methods

Patient Class

Public Class Doctor extends Person {

Private Date dateOfArrival;

Private int age;

}
Q 5 if the system two more types of Patient (InPatient,OutPatient) then we can apply inheritance
concept on Patient

Store all common info of Paitent in SupperClass and then InPatient and outpatient will extends them

Class Patient extends Person {

// Common info

Age and date of arrival

Class InPatient extends Patient{

// Common info

Private bedNo

// etc

And OutPateint also extend Patient samly

Q6

Public class Clinical Test {

Private String testName;

Private Boolean isPositive;

Q7

Public class CheckUp {

Private Paatient patient;

Private Doctor doctor;

Private Date dateAndTime;

Private ClinicalTest clinicalTest;

Public CheckUp(Paatient patient,Doctore doc, Date checkupDate, ClinicalTest clinicalTest) {


This.patient = patient;

This.doctor = doc;

This.dateAndTime = checkupDate;

This.clinicalTest = clinicalTest;

Setter and getter methods

@Override

Public String toString() {

String detail = “ Patient Name ”+ patient.getName()+

“ ID ”+ patient.getId()+

“ Address”+ patient.getAddress()+

“ Contact No”+ patient.getContactN0()+

“Age”+ patient.getAge()+

“\n Doctore Name ”+doctore.getName()+

“ Address ”+doctore.getAddress()+

“ contact no ”+doctore.getContactNo()+

“ Specialization ”+doctore.getSpecialization()+

“ Date OF Birth ”+doctore.getDateOfBirth()+

“ Date OF Hiring ”+doctore.getDateOFHiring()+

“ \n Time OF CheckUp ”+this.getDateAndTime()+

“ \n Clinical Detail ”+clinicalTest.isTestPositive()+

Return detail;

}
}

Q8

Public Class Main {

Public static void main(String[] arg) {

Patient patient = new Patient();

set all Patient information by setter methods

Doctor doctor = new Doctor();

Set all doctor by setter method

ClinicalTest test = new ClinicalTest();

Set clinical test detail

ChechUp checkup = new CheckUp(patient,doctor,new Date(),clinicalTest);

// show all records

Checkup.toString();

You might also like