top of page

Keep Reading !

You can also checkout more topics like...

peep-101_edited.png
EXPLORE COURSES (6).png
EXPLORE COURSES (9).png
EXPLORE COURSES (7)_edited.jpg

Hospital Data Base

Updated: Mar 19, 2023

Habibi Hospital has a database system that has got the details of all its patients. The database's first page contains only the name and Identity numbers of all the patients. Hospital management plans to collect these details (ie Identity number and Name) from all the patients who come for consultation for the second time. Given the Identity number and the name, provide if the Id is valid and also the number of valid ID counts by writing a program.


Note:

The hospital management framed that the identity number is valid if it is a 4 digit alphanumeric and has digits in the first two places and alphabets in the last two places. If any patient gives a Invalid Identity number, then further collecting of the Identity number is stopped.



Input Format :


First Input is a string that denotes the Identity number of the patient.

Second Input is a string that corresponds to the name of the patient.

Third Input is a string that indicates if the patient Identity is valid or not.


Output Format :

Output is an Integer that corresponds to the Number of entries of patients or displays a message that the Ids are Invalid if the Ids are not valid.


Sample Input 1:

43Sd

Harini

yes

26HJ

Harish

yes

89Jk

Vino

no


Sample Output 1:

3





Sample Input 2:

43Sd

Harini

yes

265J



Sample Output 2:

1




import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);

        //For unlimited valu storage
        ArrayList<String> value = new ArrayList<>();

        // .hasNextLine() for heckimg there are any new line input or not
        while(scn.hasNextLine() == true)
        {
            // taking the inputs
            value.add(scn.next());
        }

        // variable for maintaining the totatl no. of valid data
        int count = 0;

        //for internal data validation
        int countIn  = 0;



        //iterate over the ArrayList and checking for valid input
        for(int i = 0; i<value.size(); i++)
        {
                //Checking for patient id => alphanumeric
                if((value.get(i).length()==4) && countIn == 0)
                {

                    String id = value.get(i);

                    for(int j = 0; j<id.length(); j++)
                    {
                        if((id.charAt(j)>='0' && id.charAt(j)<='9'))
                        {
                            countIn++;
                            break;
                        }
                    }
                } //Checking the name
                else if ((countIn == 1) && (value.get(i).equals("yes") != true  && value.get(i).equals("no") != true))
                {
                    String name = value.get(i);
                    for(int j = 0; j<name.length(); j++)
                    {
                        if((name.charAt(j)>='0' && name.charAt(j)<='9'))
                        {
                            countIn = 0;
                            break;
                        }

                        if(countIn == 1)
                        {
                            countIn++;
                        }
                    }

                }//for checking yes no
                else if(countIn == 2)
                {
                    String yN = value.get(i);
                    if(yN.equals("yes") || yN.equals("no"))
                    {
                        countIn++;
                    }
                    else{
                        countIn = 0;
                    }
                }

                //if my internal COUnt is = 3 then my main valid count = count+1;
                if(countIn == 3)
                {
                    count++;
                    countIn = 0;
                }
        }

        System.out.println(count);

        
    }
}

210 views0 comments

Recent Posts

See All
bottom of page