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

Healthcare

The document contains a Java program for a healthcare information system that allows users to add and view health records for patients. It defines two main classes: Patient, which holds patient details, and HealthRecord, which manages a collection of health records. The program runs in a loop, offering options to add a record, view a record, or exit the application.

Uploaded by

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

Healthcare

The document contains a Java program for a healthcare information system that allows users to add and view health records for patients. It defines two main classes: Patient, which holds patient details, and HealthRecord, which manages a collection of health records. The program runs in a loop, offering options to add a record, view a record, or exit the application.

Uploaded by

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

import java.util.

HashMap;

import java.util.Map;

import java.util.Scanner;

class Patient {

private String name;

private int age;

private String gender;

private String address;

private String contactNumber;

public Patient(String name, int age, String gender, String address, String contactNumber) {

this.name = name;

this.age = age;

this.gender = gender;

this.address = address;

this.contactNumber = contactNumber;

public String getName() {

return name;

public int getAge() {

return age;

}
public String getGender() {

return gender;

public String getAddress() {

return address;

public String getContactNumber() {

return contactNumber;

@Override

public String toString() {

return "Name: " + name + "\nAge: " + age + "\nGender: " + gender + "\nAddress: " +
address +

"\nContact Number: " + contactNumber;

class HealthRecord {

private Map<String, String> records;

public HealthRecord() {

records = new HashMap<>();

public void addRecord(String patientName, String healthInfo) {


records.put(patientName, healthInfo);

System.out.println("Health record added successfully.");

public void viewRecord(String patientName) {

if (records.containsKey(patientName)) {

String healthInfo = records.get(patientName);

System.out.println("Health record for " + patientName + ":");

System.out.println(healthInfo);

} else {

System.out.println("No health record found for " + patientName + ".");

public class HealthcareInformationSystemDemo {

public static void main(String[] args) {

HealthRecord healthRecord = new HealthRecord();

Scanner scanner = new Scanner(System.in);

boolean running = true;

while (running) {

System.out.println("1. Add health record");

System.out.println("2. View health record");

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

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


int choice = scanner.nextInt();

scanner.nextLine(); // Consume the newline character

switch (choice) {

case 1:

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

String patientName = scanner.nextLine();

System.out.print("Enter health information: ");

String healthInfo = scanner.nextLine();

healthRecord.addRecord(patientName, healthInfo); inherit

break;

case 2:

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

String name = scanner.nextLine();

healthRecord.viewRecord(name);

break;

case 3:

running = false;

break;

default:

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

break;

System.out.println();
}

System.out.println("Exiting the program.");

scanner.close();

}1

You might also like