COP3804 Summer, 2015 Assignment #3 – Medical Administration

advertisement
COP3804
Summer, 2015
Assignment #3 – Medical Administration System – Phase 3
Last updated 07/21/2015 03:50 pm
For assignment number 3, we are going to add data persistence through the use of serialization
and we are going to add an implementation of a linked list.
Below is the list of modifications we are making to the project (feel free to use the solution for
phase 2 that I sent via email).
Make the following classes implement the Serializable interface.
Person
Diagnosis
Procedure
Visit
Clinic
VisitLinkedList class:
Modification 1: Create a class called VisitLinkedList that implements a linked list containing a Visit
object inside each node. Use the LinkedList1 class in the book as a guide (Code Listing 20-2 in page
1178) keeping in mind that the class in the book has a String value inside each node, while your
version has a Visit object inside each node.
Modification 2: Make both the VisitLinkedList and the Node classes implement the Serializable
interface.
Modification 3: Add a find method that has one parameter of type Visit and also returns a Visit
object. This method traverses the nodes in the list looking for a node whose value is the same as
the Visit object passed as an argument. If such node is found, the node’s value is returned.
Otherwise, the method returns null.
public Visit find(Visit visit)
{
}
Modification 4: Add a getVisit method that has one parameter of type int and returns the Visit
object stored in the node at the position specified by the index parameter.
public Visit getVisit(int index)
{
}
MedAdminUtility class
Modification 1: Add a public static method called serializeObject that has two parameters the first one is
of type Object and that is the object that needs to be serialized. The second parameter is of type String
and that is the file name that the serialized object is being written to. This method returns no value. The
following is the method signature:
public static void serializeObject(Object objectToSerialize, String
serializationFileName)
Modification 2: Add a public static method called deSerializeObject that has one parameter of type
String, which is the file name that the serialized object is being read from. It returns the
deserialized object read from the file.
The following is the method signature:
public static Object deSerializeObject(String serializationFileName)
Important: Both of these methods handle the exceptions: they have try and catch blocks and do
not have a throws clause after the method name.
They also have a finally clause where they call the close method on the FileOutputStream,
ObjectOutputStream, FileInputStream, and ObjectInputStream variables respectively.
Alternatively, you may use a try-with-resources block.
Group Member Responsibilities:
Group Member 1



Group Member 2


Group Member 3

Make all classes mentioned above implement Serializable.
The following methods in the VisitLinkedList class:
o size
o add(Visit v)
The serializeObject method in the MedAdminUtility class.
The following methods in the VisitLinkedList class:
o toString
o add(int index, Visit v)
o getVisit
The deSerializeObject method in the MedAdminUtility class.
Write the declaration for the VisitLinkedList class including the
instance variables and the constructor, as well as the entire
Node private inner class.
Group Member 4

The following methods in the VisitLinkedList class:
o remove(int index)

The following methods in the VisitLinkedList class:
o isEmpty
o remove(Visit element)
o find
Add the following methods to the MedAdminUtility class:
/**
* The findPatient method iterates through all the elements in the list
passed as the first argument
* and returns the element in the list found to have the id passed as
the second argument.
* If no element is found to have that id, it returns null.
* @param patientList the ArrayList of Patient elements to be searched.
* @param id the patient id to search for in the list.
* @return The element in the list that has the specified id. Null, if
none
* is found.
*/
public static Patient findPatient(ArrayList<Patient> patientList, int
id)
{
for(Patient patientElement: patientList)
{
if( patientElement.getPatientID() == id )
return patientElement;
}
return null;
}
/**
* The findDoctor method iterates through all the elements in the list
passed as the first argument
* and returns the element in the list found to have the id passed as
the second argument.
* If no element is found to have that id, it returns null.
* @param doctorList the ArrayList of Doctor elements to be searched.
* @param id the doctor id to search for in the list.
* @return The element in the list that has the specified id. Null, if
none
* is found.
*/
public static Doctor findDoctor(ArrayList<Doctor> doctorList, int id)
{
for(Doctor doctorElement: doctorList)
{
if( doctorElement.getDoctorID() == id )
return doctorElement;
}
return null;
}
/**
* The findDiagnosis method iterates through all the elements in the
list passed as the first argument
* and returns the element in the list found to have the code passed as
the second argument.
* If no element is found in the list to be have that code, it returns
null.
* @param diagnosisList the ArrayList of Diagnosis elements to be
searched.
* @param code the code to search for in the list.
* @return The element in the list that has the specified code. Null, if
none if found.
*/
public static Diagnosis findDiagnosis(ArrayList<Diagnosis>
diagnosisList, String code)
{
for(Diagnosis diagnosisElement: diagnosisList)
{
if( diagnosisElement.getCode().equals(code) )
return diagnosisElement;
}
return null;
}
/**
* The findProcedure method iterates through all the elements in the
list passed as the first argument
* and returns the element in the list found to have the code passed as
the second argument.
* If no element is found in the list to be have that code, it returns
null.
* @param procedureList the ArrayList of Procedure elements to be
searched.
* @param code the code to search for in the list.
* @return The element in the list that has the specified code. Null, if
none if found.
*/
public static Procedure findProcedure(ArrayList<Procedure>
procedureList, String code)
{
for(Procedure procedureElement: procedureList)
{
if( procedureElement.getCode().equals(code) )
return procedureElement;
}
return null;
}
/**
* The setLastAssignedPatientID method stores a value in the
lastAssignedPatientID field.
* @param newID the new value to store in lastAssignedPatientID.
*/
public static void setLastAssignedPatientID(int newID)
{
lastAssignedPatientID = newID;
}
/**
* The setLastAssignedDoctorID method stores a value in the
lastAssignedDoctorID field.
* @param newID the new value to store in lastAssignedDoctorID.
*/
public static void setLastAssignedDoctorID(int newID)
{
lastAssignedDoctorID = newID;
}
Add the following method to the VisitLinkedList class:
public VisitLinkedList copy()
{
VisitLinkedList newList = new VisitLinkedList();
Node element = first;
Visit val = null;
while( element != null )
{
if( element.value != null )
newList.add(element.value.copy());
else
newList.add(null);
element = element.next;
}
return newList;
}
Download