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

Task 3#

Rizals life documents

Uploaded by

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

Task 3#

Rizals life documents

Uploaded by

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

Back-end code of Hospital Management System.

import java.util.ArrayList;
import java.util.Scanner;

class Patient {
private String name;
private int age;
private String illness;

public Patient(String name, int age, String illness) {


this.name = name;
this.age = age;
this.illness = illness;
}

public String toString() {


return "Name: " + name + ", Age: " + age + ", Illness: " + illness;
}

public String getName() {


return name;
}
}

class HospitalManagementSystem {
private ArrayList<Patient> patients;

public HospitalManagementSystem() {
patients = new ArrayList<>();
}

public void addPatient() {


Scanner scanner = new Scanner(System.in);
System.out.print("\nEnter patient's name: ");
String name = scanner.nextLine();
System.out.print("Enter patient's age: ");
int age = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter patient's illness: ");
String illness = scanner.nextLine();
Patient patient = new Patient(name, age, illness);
patients.add(patient);
System.out.println("\nPatient added successfully.");
}

public void viewPatients() {


if (patients.isEmpty()) {
System.out.println("\nNo patients in the system.");
} else {
System.out.println("\nList of Patients:");
for (Patient patient : patients) {
System.out.println(patient);
}
}
}

public void dischargePatient() {


Scanner scanner = new Scanner(System.in);
System.out.print("\nEnter the name of the patient to discharge: ");
String name = scanner.nextLine();
for (Patient patient : patients) {
if (patient.getName().equalsIgnoreCase(name)) {
patients.remove(patient);
System.out.println("\nPatient discharged successfully.");
return;
}
}
System.out.println("\nPatient not found.");
}

public void run() {


Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("\nHospital Management System");
System.out.println("1. Add Patient");
System.out.println("2. View Patients");
System.out.println("3. Discharge Patient");
System.out.println("4. Exit");
System.out.print("Choose an option (1-4): ");

int choice = scanner.nextInt();


scanner.nextLine();

switch (choice) {
case 1:
addPatient();
break;
case 2:
viewPatients();
break;
case 3:
dischargePatient();
break;
case 4:
System.out.println("\nExiting the system. Goodbye!");
return;
default:
System.out.println("\naInvalid choice. Please try again.");
}
}
}
}

public class Main {


public static void main(String[] args) {
HospitalManagementSystem system = new HospitalManagementSystem();
system.run();
}
}

Contribution of Member:

Giving Ideas:
Guevarra, Justine L.
Guzman, Edward Joseph D.
Garcia, Ivan Matthew F.
Marticio, Carl James V.
Alfonso, Lhary Jannel
Lintag, Irish Joy
Juarez, Aleah

Provide Laptop:

Flores, Heather Jean H.


Reyes, Joshua A.

They review the lesson.


Lusung, Nicole Faith
Lero, Archel S.

All of the members provided ideas while doing the task.

You might also like