You are on page 1of 3

/* Assignment 10

* Aim: Maintaining and sorting the records of a nursing home.


*/
import java.io.*;
class Assignment_10
{ public static void main() throws IOException
{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int i,j,temp_int,flag,del_admno,choice;
String temp_str,date;
char temp_char;
int admno[]=new int [10];
String admdate[]=new String[10];
String name[]=new String[10];
int age[]=new int[10];
char g[]=new char[10];

for (i=0;i<5;i++)
{ System.out.println("Enter the Admission Number of Patient "+(i+1));
admno[i]=Integer.parseInt(br.readLine());
System.out.println("Enter the Date of Admission of Patient "+(i+1)+ " in Format DD/MM/YY");
admdate[i]=br.readLine();
System.out.println("Enter the Name of Patient "+(i+1));
name[i]=br.readLine();
System.out.println("Enter the Age of Patient "+(i+1));
age[i]=Integer.parseInt(br.readLine());
System.out.println("Enter the Gender of Patient "+(i+1)+" as M or F ");
g[i]=br.readLine().charAt(0);System.out.println();
}// end of for loop
System.out.println("Menu:\n 1. Display the list of Male Patients");
System.out.println(" 2. Display the list of Patients Admitted on a Specific Date");
System.out.println(" 3. Display the list of patients in Ascending Order of their Age");
System.out.println(" 4. To Enter a New Entry");
System.out.println(" 5. Delete an existing Entry\n 6. Exit");
do{
System.out.println("Enter choice");
choice=Integer.parseInt(br.readLine());
flag=0;
switch (choice)

{ case 1:
for (i=0;i<10;i++)//displaying the list of male patients
{ if(g[i]=='M')
flag++;
if(flag==1 && g[i]=='M')
System.out.println("Admission No.\tAdmission Date\tName\t\tAge\tGender");
if(g[i]=='M')
System.out.println(admno[i]+"\t\t "+admdate[i]+"\t"+name[i]+"\t "+age[i]+"\t "+g[i]+"\t");
}//end of for loop
if(flag==0)
System.out.println("No Male Patients admitted in the Nursing Home"); break;

case 2://displaying patients admitted on a certain date


System.out.println("Enter the Date to be Searched");date=br.readLine();
for (i=0;i<10;i++)
{ if(date.equals(admdate[i]))
flag++;
if(flag ==1 && date.equals(admdate[i]))
System.out.println("Admission No.\tAdmission Date\tName\t\tAge\tGender");
if(date.equals(admdate[i]))
System.out.println(admno[i]+"\t\t "+admdate[i]+"\t"+name[i]+"\t "+age[i]+"\t "+g[i]+"\t");
}//end of for loop
if(flag==0)
System.out.println("No Patients were Admitted on "+date); break;

case 3:
for(i=0;i<9;i++)//Sorting the data in ascending order of age through Bubble Sort
{ for(j=0;j<9-i;j++)
{ if (age[j] > age[j+1])
{ temp_int=age[j];age[j]=age[j+1];age[j+1]=temp_int;
temp_int=admno[j];admno[j]=admno[j+1];admno[j+1]=temp_int;
temp_str=admdate[j];admdate[j]=admdate[j+1];admdate[j+1]=temp_str;
temp_str=name[j];name[j]=name[j+1];name[j+1]=temp_str;
temp_char=g[j];g[j]=g[j+1];g[j+1]=temp_char;
}//end of if
}//end of inner for loop
}//end of outer for loop
System.out.println("List of Patients in Ascending order of Age ");
System.out.println("Admission No.\tAdmission Date\tName\t\tAge\tGender");
for (i=0;i<10;i++)
{ if(age[i]>0)
System.out.println(admno[i]+"\t\t "+admdate[i]+"\t"+name[i]+"\t "+age[i]+"\t "+g[i]+"\t");
}//end of for loop
break;

case 4:
for(i=0;i<10;i++)//entering a new entry
{ if(admno[i]==0)
{ System.out.println("Enter the Admission Number of the Patient");
admno[i]=Integer.parseInt(br.readLine());
System.out.println("Enter the Date of Admission in format DD/MM/YY");
admdate[i]=br.readLine();
System.out.println("Enter the Name of the Patient");
name[i]=br.readLine();
System.out.println("Enter the Age of the Patient");
age[i]=Integer.parseInt(br.readLine());
System.out.println("Enter the Gender of the Patient as M or F");
g[i]=br.readLine().charAt(0);
flag=1;break;
}//end of if
}//end of for loop
if(flag==0)
System.out.println("There are no vacancies in the Nursing Home"); break;

case 5://deleting an existing entry


System.out.println("Enter the Admission Number of Patient whose Record is to be Deleted");
del_admno=Integer.parseInt(br.readLine());
for (i=0;i<10;i++)
{ if (admno[i]==del_admno)
{ System.out.println("Patient: " +name[i]+" Discharged from Nursing Home in Good Health");
admno[i]=0;admdate[i]="";name[i]="";age[i]=0;g[i]=' ';flag=1;break;
}//end of if
}//end of for loop
if(flag==0)
System.out.println("No Admission Numbers Matched the Search");break;

case 6:
System.out.println("Exiting");break;
default:System.out.println("Wrong Choice");
}//end of switch
}while(choice!= 6); //end of do while loop
}//end of main
}//end of class

You might also like