Thursday, March 13, 2025

Java program for a hospital management system

 Here's a simple Java program for a hospital management system:


```

import java.util.ArrayList;

import java.util.Scanner;


class Patient {

    private String name;

    private int age;

    private String disease;

    private String doctor;


    public Patient(String name, int age, String disease, String doctor) {

        this.name = name;

        this.age = age;

        this.disease = disease;

        this.doctor = doctor;

    }


    public String getName() {

        return name;

    }


    public int getAge() {

        return age;

    }


    public String getDisease() {

        return disease;

    }


    public String getDoctor() {

        return doctor;

    }

}


class Doctor {

    private String name;

    private String specialization;


    public Doctor(String name, String specialization) {

        this.name = name;

        this.specialization = specialization;

    }


    public String getName() {

        return name;

    }


    public String getSpecialization() {

        return specialization;

    }

}


public class HospitalManagement {

    private ArrayList<Patient> patients;

    private ArrayList<Doctor> doctors;

    private Scanner scanner;


    public HospitalManagement() {

        patients = new ArrayList<>();

        doctors = new ArrayList<>();

        scanner = new Scanner(System.in);

    }


    public void addPatient() {

        System.out.print("Enter patient name: ");

        String name = scanner.nextLine();

        System.out.print("Enter patient age: ");

        int age = scanner.nextInt();

        scanner.nextLine(); // Consume newline left-over

        System.out.print("Enter patient disease: ");

        String disease = scanner.nextLine();

        System.out.print("Enter doctor's name: ");

        String doctorName = scanner.nextLine();

        patients.add(new Patient(name, age, disease, doctorName));

    }


    public void addDoctor() {

        System.out.print("Enter doctor's name: ");

        String name = scanner.nextLine();

        System.out.print("Enter doctor's specialization: ");

        String specialization = scanner.nextLine();

        doctors.add(new Doctor(name, specialization));

    }


    public void displayPatients() {

        System.out.println("\nPatient List:");

        for (Patient patient : patients) {

            System.out.println("Name: " + patient.getName());

            System.out.println("Age: " + patient.getAge());

            System.out.println("Disease: " + patient.getDisease());

            System.out.println("Doctor: " + patient.getDoctor());

            System.out.println();

        }

    }


    public void displayDoctors() {

        System.out.println("\nDoctor List:");

        for (Doctor doctor : doctors) {

            System.out.println("Name: " + doctor.getName());

            System.out.println("Specialization: " + doctor.getSpecialization());

            System.out.println();

        }

    }


    public void run() {

        while (true) {

            System.out.println("\nHospital Management System");

            System.out.println("1. Add Patient");

            System.out.println("2. Add Doctor");

            System.out.println("3. Display Patients");

            System.out.println("4. Display Doctors");

            System.out.println("5. Exit");

            System.out.print("Enter your choice: ");

            int choice = scanner.nextInt();

            scanner.nextLine(); // Consume newline left-over

            switch (choice) {

                case 1:

                    addPatient();

                    break;

                case 2:

                    addDoctor();

                    break;

                case 3:

                    displayPatients();

                    break;

                case 4:

                    displayDoctors();

                    break;

                case 5:

                    System.exit(0);

                    break;

                default:

                    System.out.println("Invalid choice. Please try again.");

            }

        }

    }


    public static void main(String[] args) {

        HospitalManagement management = new HospitalManagement();

        management.run();

    }

}

```


*Example Output:*

```

Hospital Management System

1. Add Patient

2. Add Doctor

3. Display Patients

4. Display Doctors

5. Exit

Enter your choice: 1


Enter patient name: John Doe

Enter patient age: 30

Enter patient disease: Flu

Enter doctor's name: Dr. Smith


Hospital Management System

1. Add Patient

2. Add Doctor

3. Display Patients

4. Display Doctors

5. Exit

Enter your choice: 3


Patient List:

Name: John Doe

Age: 30

Disease: Flu

Doctor: Dr. Smith

```


This program defines three classes: `Patient`, `Doctor`, and `HospitalManagement`. The `Patient` class has private member variables for patient details and public methods for accessing those details. The `Doctor` class has private member variables for doctor details and public methods for accessing those details. The `HospitalManagement` class has private member variables for patient and doctor lists, as well as public methods for adding patients and doctors,

C++ program for a medical shop

 Here's a simple C++ program for a medical shop:




#include <iostream>

#include <string>

using namespace std;


class Medicine {

private:

    string name;

    double price;

    int quantity;


public:

    void inputDetails() {

        cout << "Enter medicine name: ";

        cin.ignore();

        getline(cin, name);

        cout << "Enter medicine price: ";

        cin >> price;

        cout << "Enter medicine quantity: ";

        cin >> quantity;

    }


    void displayDetails() {

        cout << "\nMedicine Details\n";

        cout << "Name: " << name << endl;

        cout << "Price: $" << price << endl;

        cout << "Quantity: " << quantity << endl;

    }


    double calculateTotalPrice(int qty) {

        return price * qty;

    }


    void updateQuantity(int qty) {

        quantity -= qty;

    }

};


class MedicalShop {

private:

    string shopName;

    string address;

    Medicine medicines[10];

    int numberOfMedicines;


public:

    void inputShopDetails() {

        cout << "Enter shop name: ";

        cin.ignore();

        getline(cin, shopName);

        cout << "Enter shop address: ";

        getline(cin, address);

    }


    void addMedicine() {

        medicines[numberOfMedicines].inputDetails();

        numberOfMedicines++;

    }


    void displayMedicineDetails() {

        for (int i = 0; i < numberOfMedicines; i++) {

            medicines[i].displayDetails();

        }

    }


    void sellMedicine() {

        string medicineName;

        int quantity;

        cout << "Enter medicine name: ";

        cin.ignore();

        getline(cin, medicineName);

        cout << "Enter quantity to sell: ";

        cin >> quantity;

        for (int i = 0; i < numberOfMedicines; i++) {

            if (medicines[i].name == medicineName) {

                if (medicines[i].quantity >= quantity) {

                    double totalPrice = medicines[i].calculateTotalPrice(quantity);

                    medicines[i].updateQuantity(quantity);

                    cout << "Total price: $" << totalPrice << endl;

                } else {

                    cout << "Insufficient quantity." << endl;

                }

                return;

            }

        }

        cout << "Medicine not found." << endl;

    }


    void displayShopDetails() {

        cout << "\nShop Details\n";

        cout << "Name: " << shopName << endl;

        cout << "Address: " << address << endl;

    }

};


int main() {

    MedicalShop shop;

    int choice;

    shop.numberOfMedicines = 0;

    shop.inputShopDetails();

    while (true) {

        cout << "\nMedical Shop Management System\n";

        cout << "1. Add medicine\n";

        cout << "2. Display medicine details\n";

        cout << "3. Sell medicine\n";

        cout << "4. Display shop details\n";

        cout << "5. Exit\n";

        cout << "Enter your choice: ";

        cin >> choice;

        switch (choice) {

            case 1:

                shop.addMedicine();

                break;

            case 2:

                shop.displayMedicineDetails();

                break;

            case 3:

                shop.sellMedicine();

                break;

            case 4:

                shop.displayShopDetails();

                break;

            case 5:

                return 0;

            default:

                cout << "Invalid choice. Please try again.\n";

        }

    }

    return 0;

}


*Example Output:*


Enter shop name: Medical Shop

Enter shop address: 123 Main St


Medical Shop Management System

1. Add medicine

2. Display medicine details

3. Sell medicine

4. Display shop details

5. Exit

Enter your choice: 1


Enter medicine name: Paracetamol

Enter medicine price: 10

Enter medicine quantity: 100


Medical Shop Management System

1. Add medicine

2. Display medicine details

3. Sell medicine

4. Display shop details

5. Exit

Enter your choice: 3


Enter medicine name: Paracetamol

Enter quantity to sell: 5


Total price: $50


Medical Shop Management System

1. Add medicine

2. Display medicine details

3. Sell medicine

4. Display shop details

5. Exit

Enter your choice: 4


Shop Details

Name: Medical Shop

Address: 123 Main St



This program defines two classes: `Medicine` and `MedicalShop`. The `Medicine` class has private member variables for medicine details and public methods for inputting details, displaying details, calculating the total price, and updating the quantity. The `MedicalShop` class has private member variables for shop details and medicine data, as well as public methods for inputting shop

Featured posts

Ethiopian culture calendar language

Ethiopian culture, calendar, language  The Ethiopian language, specifically Amharic, uses a script called Ge'ez script. It consists of 3...

Popular posts