Hospital Management System
This program models a hospital management system.
Problem Statement
Write a Java program to model Doctor and Patient classes with interaction.
Source Code
| 1 | class Patient { |
| 2 | String name; |
| 3 | Patient(String n){ name=n; } |
| 4 | void getTreatment(){ System.out.println(name+" is getting treatment"); } |
| 5 | } |
| 6 | class Doctor { |
| 7 | String name; |
| 8 | Doctor(String n){ name=n; } |
| 9 | void treat(Patient p){ System.out.println(name+" treats "+p.name); } |
| 10 | } |
| 11 | public class HospitalManagement { |
| 12 | public static void main(String[] args) { |
| 13 | System.out.println("Eduinq Hospital Management"); |
| 14 | Patient p=new Patient("Arun"); |
| 15 | Doctor d=new Doctor("Rahul"); |
| 16 | d.treat(p); p.getTreatment(); |
| 17 | } |
| 18 | } |
Program Output
Eduinq Hospital Management Rahul treats Arun Arun is getting treatment
Explanation
Doctor and Patient classes model hospital scenario. - Doctor interacts with Patient via treat() method. - Patient responds with getTreatment(). - This demonstrates object interaction and encapsulation in real world modeling. Conclusion: Shows how to model hospital management system using OOP.