public class Patient extends Person Properties private in
public class Patient extends Person {
//=========== Properties ===============
private int pId;
private String address;
//=========== Constructors =============
public Patient(){
super();//set 4 properties to blank
pId = 0;
address = \"\";
}
public Patient(int p,String f,String l,String e, int pi,String a){
super(p,f,l,e);//pass 4 properties to super class
pId = pi;
address = a;
}
//=========== Behavior =================
public void setPId( int pi){pId = pi;}
public int getPId(){
return pId;}
public void setAddress(String a){address = a;}
public String getAddress(){
return address;}
public void display(){
super.display();//calls display in the super class to display 4 properties
System.out.println(\"Patient Id = A\"+getPId());
System.out.println(\"Address = \"+getAddress());
}//end display()
public static void main(String args[]){
//Object 1
Patient pa1;
pa1 = new Patient();//calls no arg constructor
pa1.setPId(900);
pa1.setAddress(\"Marietta\");
pa1.display();
System.out.println(\"\ \");//space between to objects
//Object 2
Patient pa2;
pa2 = new Patient(1234,\"Jimmy\",\"Hawkins\",\"jhawkins@yahoo.com\",901,\"Acworth\");
//calls multi argument constructor
pa2.display();
}//end main
}//end class
Let’s make it so that we can look up and find a Patient in the “Patients.txt” file. The Patients are organized by Patients Code. So we should be able to look in the File for Patient “A900”, and it should give us back all the data about that Patient, like, Patinet Id, etc. So we will need to read from the “Patients.txt” file and select the Patient Id “A900”. The File is delimited by “:”(colons). Take a look at the file. use FileInputStream and Buffered reader to read from the file.
Code for testing ‘Select’ that goes in main:
Patient p1 = new Patient();
p1.select(“A900”);
p1.display();
Let’s also make it so that we can add a new Patient to the “Patients.txt” file.use PrintStream and Buffered writer to write to the file. We should be able to append a new line to the “Patients.txt” file with all the data for a new Patient, like PatientId,etc.
Code for testing ‘Insert’ that goes in main:
Patient p1 = new Patient();
p1.insert(“A900\",\"1234\",\"Jimmy:Hawkins\",\"Marietta\",\"jhawk@yahoo.com\",\"Cigna\");
//now go look in file to see if new line was added
Solution
import java.util.*;
public class Patient
{
private int patientId;
private String patientName;
private String patientAddress;
private String patientPhone;
private Date patientDOB;
public Patient(int patientId, String patientName, String patientAddress, String patientPhone, Date patientDOB)
{
// initialise instance variables
this.patientId = patientId;
this.patientName = patientName;
this.patientAddress = patientAddress;
this.patientPhone = patientPhone;
this.patientDOB = patientDOB;
}
public void setId (int patientId) {
this.patientId = patientId;
}
public void setName (String patientName){
this.patientName = patientName;
}
public void setAddress (String patientAddress){
this.patientAddress = patientAddress;
}
public void setPhone (String patientPhone){
this.patientPhone = patientPhone;
}
public void setDOB (Date patientDOB){
this.patientDOB = patientDOB;
}
public int getId () {
return patientId;
}
public String getName () {
return patientName;
}
public String getAddress () {
return patientAddress;
}
public String getPhone () {
return patientPhone;
}
public Date getDOB () {
return patientDOB;
}
}
}



