0% found this document useful (0 votes)
14 views13 pages

HOSPITAL

This document contains the code for a Java program that allows a user to input patient information including name, age, sex, address, room selected and days stayed in the hospital. It then calculates the bill for each patient and displays a summary. The program also allows the user to search for a specific patient's information and restart or exit the program.
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)
14 views13 pages

HOSPITAL

This document contains the code for a Java program that allows a user to input patient information including name, age, sex, address, room selected and days stayed in the hospital. It then calculates the bill for each patient and displays a summary. The program also allows the user to search for a specific patient's information and restart or exit the program.
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/ 13

package dsa;

import java.util.Scanner;

class hsptl{

//patient infos.

String Fname,Lname, sex, add;

int age;

//hospital bills

double bill, total,med;

//various amount of hospital rooms

double[] price = {

200,

1200,

2500,

10000,

3000,

4000,

3500,

2000

};

public class Main {

public static void main(String[] args) {

Scanner scan = new Scanner (System.in);

int n,num,pwd=0;

int a = 0;
double dc = .2;

//various hospital rooms

String[] rooms = {

"Ward",

"Semi Private Room",

"Private Room",

"Executive/Suit Room",

"ICU",

"NICU",

"PCIU",

"Incubator Cost"

};

String[] pwd0 = {"Yes","No"};

//use for the selection of room

int room = 0;

//start of the program

System.out.println("--------------------------------");

System.out.println("*** H O S P I T A L B I L L ***");

System.out.println("--------------------------------");

do{

//the user will enter the number of patients to be inputted to the program

System.out.print("Enter number of patient : ");

num = scan.nextInt();

System.out.println("--------------------------------");
hsptl[] ptnt = new hsptl[num];

//this loop is used for entering the patients info, this will repeat until it meets the number of
loops entered(number of patient)

for (int i = 0; i < ptnt.length ; i++)

ptnt[i] = new hsptl();

System.out.println("Patient [" + (i+1) + "] Information ");

System.out.print("First Name : ");

ptnt[i].Fname = scan.next();

System.out.print("Last Name : ");

ptnt[i].Lname = scan.next();

System.out.print("Age : ");

ptnt[i].age = scan.nextInt();

System.out.print("Sex : ");

ptnt[i].sex = scan.next();

System.out.print("Address : ");

ptnt[i].add = scan.next();

System.out.println("P.W.D.?");

System.out.println("1. " + pwd0[0] + " 2. " + pwd0[1]);

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

pwd = scan.nextInt();

if(pwd > 2)

break;

//list of hospital rooms


System.out.println("\n***ROOMS***");

System.out.println("1. " + rooms[0]);

System.out.println("2. " + rooms[1]);

System.out.println("3. " + rooms[2]);

System.out.println("4. " + rooms[3]);

System.out.println("5. " + rooms[4]);

System.out.println("6. " + rooms[5]);

System.out.println("7. " + rooms[6]);

System.out.println("8. " + rooms[7]);

//the user will select which room is the patient stayed

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

room = scan.nextInt();

if(room >= 8)

break;

//the user will enter how many days the patient stayed in the room

System.out.print("Days : ");

int day = scan.nextInt();

System.out.print("\nMedicine Bill : ");

ptnt[i].med = scan.nextInt();

//solving for subtotal bill by multiplying the room fee and days of stays

if (room == 1)

ptnt[i].bill = ptnt[i].price[0]*day;
System.out.println("Subtotal : " + ptnt[i].bill );

else if (room == 2)

ptnt[i].bill = ptnt[i].price[1]*day;

System.out.println("Subtotal : " + ptnt[i].bill );

else if (room == 3)

ptnt[i].bill = ptnt[i].price[2]*day;

System.out.println("Subtotal : " + ptnt[i].bill );

else if (room == 4)

ptnt[i].bill = ptnt[i].price[3]*day;

System.out.println("Subtotal : " + ptnt[i].bill );

else if (room == 5)

ptnt[i].bill = ptnt[i].price[4]*day;

System.out.println("Subtotal : " + ptnt[i].bill );

else if (room == 6)

ptnt[i].bill = ptnt[i].price[5]*day;
System.out.println("Subtotal : " + ptnt[i].bill );

else if (room == 7)

ptnt[i].bill = ptnt[i].price[6]*day;

System.out.println("Subtotal : " + ptnt[i].bill );

else if (room == 8)

ptnt[i].bill = ptnt[i].price[7]*day;

System.out.println("Subtotal : " + ptnt[i].bill );

else

break;

if (ptnt[i].age >= 60)

if (pwd == 1)

ptnt[i].total = (ptnt[i].bill - (ptnt[i].bill*dc))+ptnt[i].med;

System.out.println("Discount : " + ptnt[i].bill*dc + " (20%)");

System.out.println("Total Bill : " + ptnt[i].total);

else if(pwd == 2)
{

ptnt[i].total = (ptnt[i].bill - (ptnt[i].bill*dc)) + ptnt[i].med;

System.out.println("Discount : " + ptnt[i].bill*dc + " (20%)");

System.out.println("Total Bill : " + ptnt[i].total);

else

break;

else

if (pwd == 1)

ptnt[i].total = (ptnt[i].bill - (ptnt[i].bill*dc)) + ptnt[i].med;

System.out.println("Discount : " + ptnt[i].bill*dc + " (20%)");

System.out.println("Total Bill : " + ptnt[i].total);

else if(pwd == 2)

ptnt[i].total = ptnt[i].bill + ptnt[i].med;

System.out.println("Discount : No Discount");

System.out.println("Total Bill : " + ptnt[i].total);

else
{

break;

System.out.println("");

/*this loop will display all entered informations of the patient including their hospital bills*/

for(int i = 0; i < ptnt.length; i++)

if(room >= 8)

break;

if(pwd > 2)

break;

System.out.println("\nPatient #" + (i+1) + "\t");

System.out.print("First Name : " + ptnt[i].Fname + "\t");

System.out.print("Last Name : " + ptnt[i].Lname + "\t");

System.out.print("Age : " + ptnt[i].age + "\t");

System.out.print("Sex : " + ptnt[i].sex + "\t");

System.out.print("Address : " + ptnt[i].add + "\t");

System.out.print("P.W.D : " + pwd0[pwd-1] + "\t");

System.out.print("Room : " + rooms[room-1] + "\t");


System.out.print("Room Fee : " + ptnt[i].price[room-1] + "\t");

System.out.print("Medicine Bill : " + ptnt[i].med + "\t");

System.out.print("Subtotal : " + ptnt[i].bill + "\t");

if (pwd == 1 || ptnt[i].age >= 60)

System.out.print("Discount : " + ptnt[i].bill*dc + " (20%)\t");

else if (pwd == 2 && ptnt[i].age >= 60)

System.out.print("Discount : " + ptnt[i].bill*dc + " (20%)\t");

else if (pwd == 2 && ptnt[i].age < 60)

System.out.print("Discount : No Discount\t");

System.out.print("Total Bill : " + ptnt[i].total + "\t\n");

do{

if(pwd > 2)

break;

if(room > 8)

break;
}

//it is use to locate or find the informations of patients by entering the patients number

System.out.println("\n***LOCATE PATIENT***");

System.out.println("1. Locate 2. Exit");

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

a = scan.nextInt();

if (a > 2)

break;

if (a == 1)

System.out.print("\nPatient # : ");

int p = scan.nextInt();

if (p > ptnt.length)

System.out.println("\n!!!Invalid Keyword!!!");

System.out.println("!!!Out Of Range!!!");

System.out.println("!!!Patient not found!!!");

continue;

System.out.println("--------------------------------");

System.out.println("First Name : " + ptnt[p-1].Fname);

System.out.println("Last Name : " + ptnt[p-1].Lname);

System.out.println("Age : " + ptnt[p-1].age);


System.out.println("Sex : " + ptnt[p-1].sex);

System.out.println("Address : " + ptnt[p-1].add);

System.out.println("P.W.D : " + pwd0[pwd-1]);

System.out.println("Room : " + rooms[room-1]);

System.out.println("Room Fee : " + ptnt[p-1].price[room-1]);

System.out.println("Medicine Bill : " + ptnt[p-1].med);

System.out.println("Subtotal : " + ptnt[p-1].bill);

if (pwd == 1 || ptnt[p-1].age >= 60)

System.out.println("Discount : " + ptnt[p-1].bill*dc + " (20%)");

else if (pwd == 2 && ptnt[p-1].age >= 60)

System.out.println("Discount : " + ptnt[p-1].bill*dc + " (20%)");

else if (pwd == 2 && ptnt[p-1].age < 60)

System.out.println("Discount : No Discount");

System.out.println("Total Bill : " + ptnt[p-1].total);

System.out.println("--------------------------------");

}while(a != 2);

//if the user entered higher number than the rooms available in the program, the program will
close automatically

if(pwd > 2)
{

System.out.println("\n!!!Invalid Keyword!!!");

System.out.println("!!!Out Of Range!!!");

break;

if(room > 8)

System.out.println("\n!!!Invalid Keyword!!!");

System.out.println("!!!Out Of Range!!!");

break;

//if the user entered higher number than the stored patient infos, the program will close
automatically

if( a > 2)

System.out.println("\n!!!Invalid Keyword!!!");

System.out.println("!!!Out Of Range!!!");

break;

System.out.println("1. Restart");

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

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

n = scan.nextInt();

//if the user eneters 3 or higher, the program will close because it only has two choices

if (n > 2)

{
System.out.println("\n!!!Invalid Keyword!!!");

System.out.println("!!!Out Of Range!!!");

break;

System.out.println("--------------------------------");

}while(n != 2);

You might also like