Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help turing this pseudo code into code the language is Java; case PATIENT

ID: 656416 • Letter: I

Question

I need help turing this pseudo code into code the language is Java;

case PATIENT_ADD:
// write the lines of code or a method that:
// 1. create the current patient object
// 2. call that object's addPatient method
// 3. save the current patient
// 4. use the patient's first and last name to add to
// the EMRLookUp object
// 5. save the EMRLookUp object

// I have the object i just need the code to call it.

break;
  
case PATIENT_VIEW:
// write the lines of code or a method that:
// 1. create a loop from index 0 to the count of the
// patientList -1
// 2. get the string for the patient at the current index
// 3. split away the commas into first and last name
// 4. write the number of the patient (index + 1) followed
// by the patient's first and last names
break;
  
case PATIENT_LOAD:
// write the lines of code or a method that:
// 1. attempt to open the file for the patient number given
// by the user
// 1a. if the file won't open, is empty, or has size 0,
// then the file doesn't exist
// 1a1. report the file doesn't exist
// 1a2. exit this case
// 2. if the file opens, use the constructor that uses a
// a reader to create curPatient
// NOTE: if curPatient was already used, Java will overwrite
// the object for you and set the old object
// to be destroyed

break;
  
case PATIENT_DEL:
// 1. get the number of the patient to delete
// 2. remove the patient index (number-1) from
// the patientList object
// 3. save the patient list

Explanation / Answer

//Program for Patients data storing and loading

import java.util.Scanner; //Scanner as reading object
import java.io.*; //For file I/O Classes

class Patient
{
   int index=0; //to count maximum patient records in file
   Strint pno;
   String firstname;
   String lastname;
   FileWriter fw;
   FileReader fr;
   Patient() //Default constructor
   {
       pno=null;
       firstname=null;
       lastname=null;
       fr=null;
       fw=null;

    }
  
   void addPatient() //Adding patient to file
   {
       Scanner s=new Scanner(System.in); //Reading object s
       try
       {
       fw=new FileWriter("Patient.dat"); //Opening file for writing
       char ch='y'; //Repeat until any more yes
       while(ch=='y') //Loop for repeating
       {
           System.out.println("Enter Patient Number "); //Input patient's data
           pno=s.next();
           System.out.println("Enter Patient First name ");
           firstname=s.nextLine();
           System.out.println("Enter Patient Last name ");
           lastname=s.nextLine();
           fw.write(pno); //Write pno
           fw.write(firstname);fw.write(lastname); //Write lastname and first name
           System.out.println("Any more data?{y/n}:");
           ch=s.next().charAt(0); //Read any more{y/n}
       fw.close(); //Close file
       }catch(IOException ie) //If file opening or writing is failed
       {System.out.println(ie);}
   }
  
  
   void viewPatients() //View method
   {
  
               try
               {
                   fr=new FileReader("Patient.dat");//file opened for reading
                   while(fr.read()!=-1) //Repeat until end of file
                   {
                       pno=fr.read(); //Read pno, firstname and last name
                       firstname=fr.readLine();
                       lastname=fr.readLine();
                       index++; //Increase index count
                       System.out.println(index+": "+firstname+","+lastname); //Display by , seperator
                   }
               fr.close();   //Close the file
               }
               catch(IOException ie) //Handle exception if file open/reading is failed
               {System.out.println(ie);}
   }
  
   void patientLoad() //patient load method
   {
       String tpno;
               try
               {
                   fr=new FileReader("Patient.dat"); //Open file for reading
                   System.out.println("Enter Patient no. to load: ");
                   tpno=fr.next(); //Searching a pno
                  
                   while(fr.read()!=-1) //Read until eof
                   {
                       pno=fr.read(); //Read from file
                       if(pno.equals(tpno)) //Compare searching pno and tpno if found
                       {
                       firstname=fr.readLine(); //Read first name and last
                       lastname=fr.readLine();
                       System.out.println(pno+":"+firstname+","+lastname); //Display all data
                       break;
                       }
                   }
                   if(!pno.equals(tpno)) //if not found
                   System.out.println("No.such patient no. to load");
               fr.close();    //Closing file
               }
               catch(IOException ie)
               {System.out.println(ie);}
   }
  
   void patientDelete() //Delete operation
   {
       String tpno;
       String tplist[index],tfirstname[index],tlastname[index]; //Maximum size of patients array
       int i=0;
           try
               {
                   fr=new FileReader("Patient.dat"); //Opened file for reading
                   System.out.println("Enter Patient no. to delete: ");
                   tpno=fr.next(); //Reading deleting tpno
                  
                   while(fr.read()!=-1) //Reading until eof
                   {
                   pno=fr.read();
                       if(!pno.equals(tpno)) //If pno is not matched

                        {

                       tplist[i]=fr.readLine(); //copy to arrays tplist,tfirstname and tlastname
                       tfirstname[i]=fr.readLine();
                       tlastname[i]=fr.readLine();
                       i++; //Increase index
                       }
                   }
                   fr.close(); //Close file
               }
               catch(IOException ie)
               {System.out.println(ie);}
       //Writing back undelete array list to file
       try
       {
       fw=new FileWriter("Patient.dat"); //Opening file
       i=0;
       while(i<tplist.length)//Until size of array list
       {
           fw.write(tplist[i]); //Writing each of array elements
           fw.write(tfirstname[i]);
           fw.write(tlastname[i]);
           i++; //Increase for next patient data
       }
       fw.close(); //Close writing file
       }
       catch(IOException ie)
       {System.out.println(ie);}
   }
      
//ALL THE ABOVE METHODS YOU CAN CALL FROM YOUR Switch statement of Main()

                    
                      

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote