SlideShare a Scribd company logo
I've already completed the Java assignment below, but it doesn't work. I will include my code
and the tests. Please correct my code and tests to that they match what has been asked and
reached 95% test coverage as asked for in the assignment.
Assignment: Disease File Repository
This assignment is a continuation of the last assignment. Please use the Eclipse project that you
created in the first assignment for this work.
Source Code
Class: Exposure
Copy the Exposure class from the previous assignment into the new. Make the necessary
changes so that this class can be serialized.
Class: Patient
Copy Patient class from the previous assignment into the new. Make the necessary changes so
that this class can be serialized and that it uses the Exposure class class.
Class: Disease
Copy the Disease, the InfectiousDisease, the NonInfectiousDisease classes from the previous
assignment into the new. Make the necessary changes so that they can be serialized.
Class: DiseaseAndPatient
Create a class called DiseaseAndPatient and define the follwing properties:
private Disease[] diseases;
private Patients[] patients;
Create getter and setter methods for the two arrays and document the new methods using the
Javadoc standard.
Class: DiseaseFileRepository
Create a class called DiseaseFileRepository and define the following methods:
DiseaseAndPatient init(String folderPath)
This method accepts a file path to the folder where the data was serialiaed and set the folder path
to a propert on this class. Deserialize the disease data from the file named diseases.dat.
Deserialize the patient data from the file named patients.fat. Set both the deserialized disease and
patient arrays to an instance of the DiseaseAndPatient class and return that instance. Throw an
IllegalArgumentException with an appropriate message if the supplied folder path is null.
void save(Disease[] diseases, Patient[] patients)
This method serializes and saves the supplied disease and patient array data to two separate files
on the file system using the folder path from the init method. Serialize the disease array data to a
file named disease.dat and the patient array data to the file name patients.dat.
Documentation
You are required to document the class, constructor, and methods using Javadoc standard.
Class: DiseaseFileRepositoryTest
Create a class called DiseaseFileRepositoryTest to test your DiseaseFileRespository class. You
must achieve at least 95% test coverage on the DiseaseFileRepository class.
Class: DiseaseControlManager and DiseaseControlManagerImpl
Copy the DiseaseControlManager interface and the DiseaseControlMangerImpl class from the
previous assignment and into the new. The DiseaseControlManager implementation will use the
DiseaseFileRepository class that you created in this assignment to initialize and save the disease
and patient data.
Constructor
Add a DiseaseFileRepository property to the DiseaseControlManager implementation and
initialize the property in the constructor of the Disease ControlManager implementation.
Additional Methods
Add below methods to the DiseaseControlManager interface and implement the methods in the
DiseaseControlManagerImpl class:
Disease[] getDisease()
package edu.disease.asn3; public class NonInfectiousDisease extends Disease{ /** Creates a
string array containing four nonifectctious, examples * of diseases / @override public String[]
getExamples() { return new String[] { "Cardiovascular Disease", "Diabetes", "Cystic Fibrosis",
"Hypertension"}; } /** * Creates a string array containing * four nonifectctious examples * of
diseases */ @override public String[] getExamples() { return new String[] {"Cardiovascular
Disease", "Diabetes", "Cystic Fibrosis", "Hypertension"}; } }
*/ public abstract class Disease implements Serializable{ /** Properties specified in assignment
*/ UUID diseaseId; String name; /** Setter for diseaseId (1param diseaseId */ public void
setDiseaseId(UUID diseaseId) { this. diseaseId = diseaseId; } /** Getter for diseaseID (ireturn
*/ public UUID getDiseaseId() { return diseaseId; } /** Setter for name (iparam name */ public
void setName(String name) { this. name = name; } /** Getter for name (i)return */ public
String getName() { return name; } @Override public int hashCode() { return
objects.hash(diseaseId); } @Override public boolean equals(object obj) { if (this ==obj ) return
true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Disease other =
(Disease) obj; return objects.equals(diseaseId, other.disease } @override public String tostring()
{ return "Disease [diseaseId =" + diseaseId + ", } public abstract String[] getExamples();
/** Uses compareTo to sort patient by last name, then first name. The class compares the name
of the patient, compares it to the last name of another patient, then sorts it. If the last names are
the same, the first names are then compared to each other and sorted based on that. public int
compareTo(Patient name) { int lastNameComp = this.lastName.compareToIgnoreCase(name.
lastName); if (lastNameComp !=0){ return lastNameComp; else { return
this.firstName.compareToIgnoreCase (name.firstName); / * Uses compareTo to sort patient by
last name, then first name. The class * compares the name of the patient, compares it to the last
name of another * patient, then sorts it. If the last names are the same, the first names * are then
compared to each other and sorted based on that. */ public int compareTo(Patient name) { int
lastNameComp = this. lastName. compareToIgnoreCase (name. lastName); if (lastNameComp
!=0 ) { return lastNameComp; } else { return
this.firstName.compareToIgnoreCase(name.firstName); } } }
package edu.disease.asn3; import java.util.UUID; oublic interface DiseaseControlManager { / *
Method adds a disease to the application. * @param name * @param infectious * @return */
public Disease addDisease(String name, boolean infectious); / * Gets a disease * @param
diseaseId * Qreturn */ public Disease getDisease(UUID diseaseId); / * Adds a patient * @param
firstName * @param lastName * @param maxDiseases * @param maxExposures * @return */
public Patient addPatient(String firstName, String lastName, int maxDiseases, int
maxexposures); / * Gets a patient * @param patientId * @return */ public Patient
getPatient(UUID patientId); / * Connects a disease to a patient * @param patientId * @param
diseaseId */ public void addDiseaseToPatient(UUID patientId, UUID diseaseId); / * Connects
exposure status to a patient * @param patientId * @param exposure */ public void
addExposureToPatient(UUID patientId, Exposure exposure); / * Gets the disease array *
@return */ public Disease[] getDiseases(); / * Gets the patient array * @return *I public Patient[]
getPatients(); / * Calls the init method on the * DiseasefileRepository implementation. * Eparam
folderPath */ public void init(String folderPath); /** * Calls the save method on the *
DiseasefileRepository implementation * @throws Exception */ public void save() throws
Exception;
* Represents the patient by name and ID; includes exposures to * diseases and disease IDs. *
(1)author * / public class Patient implements Serializable{ /** Properties as specified in
assignment */ UUID patientId; String firstName; String lastName; Exposure[] exposures;
UUID[] diseaseIds; /** Constructor for maxDiseases/maxExposures w/ Exception * @param
maxDiseases * eparam maxExposures */ public Patient(int maxDiseases, int maxExposures) { if
(maxDiseases <=0 maxExposures <=0 ) { } throw new IllegalArgumentException("Invaild
input. "); this. diseaseIds = new UUID[maxDiseases]; this. exposures = new
Exposure[maxDiseases ]; } /** Method for Disease array; adds diseaseId to array * (iparam
diseaseId */ public void addDiseaseId(UUID diseaseId) { for (int i=0; i< diseaseIds.length; i++ )
{ if (diseaseIds[i] == null) { diseaseIds [i]= diseaseId; return; } } } throw new
IndexOutofBoundsException("Index is full."); /** Method of Exposure array * eparam exposure
*/ public void addExposure(Exposure exposure) { for (int i=0; i< exposures.length; i++ ) { if
(exposures[i] == null) { exposures [i]= exposure; return; } } } throw new
IndexOutofBoundsException("Index is full."); /** Setter for patientID * @iparam patientID */
public void setPatientId(UUID patientID) { this. patientId = patientID; } /** Getter for
patientID * @ireturn */ public UUID getPatientId() { return patientId; }
package edu.disease.asn3; import java.io.*; import java.nio.file.Paths; / * This class is includes
methods for * creating and saving information for * the disease and patients arrays in * the
DiseaseAndPatient class. */ public class DiseasefileRepository { / * Serialization is when a
object is converted to a series * or sequence of bytes. The bytes include information about * the
object's data type. This information can then be written * into a file. Desecialization is the
reverse process and the * objects information can then be read from that file. * The private static
final long property called serialversionUID * is written so that the user can make make changes
as they wish * without relying on the system to generate one and then matching * the ID against
multiple classes. * @param folderPath * @return */ private static String folderPath = "path"; / *
Constructor that initializes * with folder path. * eparam folderPath */ public
DiseasefileRepository() { if (folderPath == null) { } throw new
IllegalArgumentException("Error: Folder path is null."); } this. folderPath = folderPath; / * This
method serializes * disease information. * @param diseases * @throws FileNotFoundException
* @throws IOException / public void serializeDiseases(Disease[] diseases) throws
FileNotFoundException, IOException { try (FileoutputStream fout = new
FileOutputStream(Paths.get(folderPath, "disease.dat").toString ()); ObjectOutputStream out =
new ObjectOutputStream(fout)) { } out.writeobject(diseases); } / * This method desecializes *
disease information. * @return * @throws FileNotFoundException * @throws IOException *
@throws ClassNotFoundException */ public Disease[] deserializeDiseases() throws
FileNotFoundException, IOException, ClassNotFoundException { try (FileInputStream fIn=
new FileInputStream(Paths.get(folderPath, "diseases.dat"). toString ()); objectInputStream in =
new objectInputStream (fIn)){ } return (Disease[]) in.readobject(); } / * This method serializes
* patient information. * @param patients * @throws FileNotFoundException * @throws
IOException */ public void serializePatients(Patient[] patients) throws FileNotFoundException,
IoException { try (FileoutputStream fout = new FileOutputStream(Paths.get(folderPath,
"patients.dat").toString ()); ObjectOutputStream out = new ObjectOutputStream(fout)) { }
out.writeobject(patients); }
package edu.disease.asn3; import static org.junit.Assert.assertEquals; import static org.junit.
Assert.assertNotNull; import static org.junit. Assert.assertThrows; import static org.junit.
Assert.assertTrue; import java.io.FileNotFoundException; import java.io.IoException; import
org.junit.Before; import org.junit.Test; public class DiseaseFileRepositoryTest { private
DiseaseFileRepository path; @Before public void setUp() { path = new DiseaseFileRepository
(); } @Test public void testSaveAndInit() throws FileNotFoundException, IOException,
ClassNotFoundException { Disease[] diseases = new Disease[2]; Patient [] patients = new
Patient [2]; path.save(diseases, patients); DiseaseAndPatient data = path init(); Disease[]
allDiseases = data.getDiseases () ; Patient[] allPatients = data.getPatients ();
assertNotNull(allDiseases); assertNotNull(allPatients); assertEquals(2, alldiseases.length);
assertEquals(2, allpatients.length); } public void nullFolderTest() { DiseaseFileRepository rep=
new DiseaseFileRepository () ; assertThrows(FileNotFoundException.class, () -> rep.init()); }
package edu.disease.asn3; public class InfectiousDisease extends Disease{ / * Creates a string
array containing four examples of * infectious diseases. */ @override public String[]
getExamples() { } return new String[]{"CoVID-19", "Common Cold", "Influenza",
"Gastroenteritis"}; }
public UUID getPatientId() { return patientId; } /** Setter for firstName * Qparam firstiname
*/ public void setFirstName(String firstName) { this.firstName = firstName; } /** Getter for
firstName * @return */ public String getFirstName() { return firstName; } /** Setter for
lastName * Qparam lastName */ public void setLastName(String lastName) { this.lastName =
lastName; } /** Getter for lastName * @ireturn / public String getLastName() { return
lastName; } / * Getter for Exposures */ public Exposure[] getExposures() { return exposures; }
/ * Setter for Exposure */ public void setExposures(Exposure[] exsposures) { this. exposures =
exposures; } / * Setter for UUID */ public void setDiseaseIds(UUID[] diseaseIds) {
this.diseaseIds = diseaseIds; } *** * Getter for UUID / public UUID[] getDiseaseIds() { return
diseaseIds; } @override public int hashCode() { return objects.hash(patientId); } @override
public boolean equals(object obj) { if (this ==obj ) return true; if (obj == null) return false; if
(getClass() ! = obj.getClass()) return false; Patient other = (Patient) obj; } return objects.equals
(patientId, other.patientId); @override public String tostring() { return "Patient [patientId=" +
patientId + ", firstName=" + firstName + ", lastName=" + lastName + ", exposures=" +
Arrays.toString(exposures) + ", diseaseIds=" + Arrays.toString(diseaseIds) + "]"; } /
import java.util.objects; import java.util.UUID; import java.time.LocalDateTime; import
java.io.Serializable; * Represents patient via ID, local time/date infomation, and exposure type *
@author| / public class Exposure implements Serializable{ /** Properties as specified in the
assignment / private UUID patientID; private LocalDateTime dateTime; private String
exposureType; / Constructor for patientID * (iparam patientID */ public Exposure(UUID
patientID) { this. patientID = patientID; } /**Setter for patientID * (iparam patientID */ public
void setPatientID(UUID patientID) { this. patientID = patientID; } /** Getter for patientID *
(ireturn / public UUID getPatientID() { return patientID; } /** Setter for dateTime * (jparam
dateTime */ public void setDateTime(LocalDateTime dateTime) { this.dateTime = dateTime; }
/** Getter for datTime * (ireturn */ public LocalDateTime getDateTime() { return dateTime; } /
Setter for Exposure type * @param exposuretype */ public void setExposureType(String
exposureType) { if (exposureType.equals("D") || exposureType.equals("I")) { this.
exposureType = exposureType; } else { throw new IllegalArgumentException("Incorrect input.
Input either 'D' for direct exposure or 'I' for indirect."); } } /** Getter for Exposure Type *
@ireturn / public String getExposureType () { return exposureType; } /** Hash and equals as
described in assignemtn */ @Override
package edu.disease.asn3; import java.io.FileNotFoundException; [. public class
DiseaseControlManagerImpl implements DiseaseControlManager { private Disease[] diseases;
private Patient [] patients; int maxDiseases; int maxPatients; int diseaseCntr; int patientCntr;
DiseasefileRepository fileRep; / * Constructor that accepts max diseases and max * patients that
can be stored/initialize arrays * @param maxDiseases * @param folderPath * @param
maxPatientss */ public DiseaseControlManagerImpl(int maxDiseases, int maxPatients) { if
(maxDiseases < 0 maxPatients < ) { } throw new IllegalArgumentException("Error"); this
maxDiseases = maxDiseases; this.maxPatients = maxPatients; this. diseases = new Disease
[maxDiseases]; this.patients = new Patient [maxPatients]; this. diseaseCntr =0; this. patientCntr
=0; } this.fileRep = new DiseasefileRepository (); / * Creates a new Disease and stores it * in
the diseases array. Also, creates instance of * a Disease subclass. */ @override public Disease
addDisease(String name, boolean infectious) { if (diseaseCntr >= maxDiseases) { } throw new
IllegalstateException("Error"); Disease disease; if (infectious == false) { } disease = new
NonInfectiousDisease () ; else { } disease = new InfectiousDisease (); disease.setName (name);
disease. setDiseaseId(UUID. randomUUID()); new InfectiousDisease(); diseases [diseaseCntr] =
disease; diseaseCntr++; } return disease; / * Returns Disease from the array */ @override public
Disease getDisease(UUID diseaseId) { for(Disease disease : diseases) { if(disease != null &&
disease.getDiseaseId().equals(diseaseId)) { return disease; } } return null; } / * Creates a new
Paitent using arugments and * adds them to the patients array. */ @Override public Patient
addPatient(String lastName, String firstName, int maxDiseases, int maxEx if (patientCntr >=
maxPatients) { throw new IllegalstateException("Error");
@Override public int hashCode() { return objects.hash(dateTime, patientID); } @override
public boolean equals(object obj) { if (this == obj) return true; if (obj == null) return false; if
(getClass() != obj.getClass()) return false; Exposure other = (Exposure) obj; } return
objects.equals(dateTime, other.dateTime) && objects.equals(patientID, other.patientID); /
tostring as described in assignment */ @override public String tostring() { return "Exposure
[patientID=" + patientID + ", dateTime=" + dateTime + ", exposureType=" + exposureType +
"]"; }
package edu.disease.asn3; public class DiseaseAndPatient { / * Properties as specified in the *
assignement details. */ private Disease[] diseases; private Patient[] patients; / * Setter for the
Disease array * eparam diseases * / public void setDiseases(Disease[] diseases) { this. diseases
= diseases; } / * Getter for the Disease array * ereturn */ public Disease[] getDiseases() { return
diseases; } / * Setter for the Patients array * eparam patients */ public void setPatients(Patient[]
patients) { this. patients = patients; } / * Getter for the Patietns array * ereturn */ public
Patient[] getPatients() { return patients; } }
} / * Deserializes patient * information. * * @return * @throws FileNotFoundException *
@throws IOException * @throws ClassNotFoundException */ public Patient[]
deserializePatients() throws FileNotFoundException, IoException, ClassNotFoundException try
(FileInputStream fIn = new FileInputStream(Paths.get(folderPath, "patients.dat").toString());
ObjectInputstream in = new ObjectInputStream(fIn)) { return (Patient []) in.readobject(); } } /
* Uses previous methods to deserialize. * disease and patient data from the * disease.dat and
patient.dat files. * * @return * @throws IOException * @throws ClassNotFoundException *
@throws FileNotFoundException / public DiseaseAndPatient init() throws
FileNotFoundException, ClassNotFoundException, IoException { Disease[] diseases =
deserializeDiseases (); Patient [] patients = deserializePatients (); return new
DiseaseAndPatient(); } / * Serializes information disease and * patient data from the disease.dat
* and patient.dat files using methods * above. * * @param diseases * @param patients *
@throws FileNotFoundException * @throws IOException */ public void save(Disease[]
diseases, Patient[] patients) throws FileNotFoundException, IoException {
serializeDiseases(diseases); serializePatients (patients); }
} Patient patient1 = new Patient(maxDiseases, maxExposures); patient1. setPatientId(UUID.
randomUUID ()); patient1.setLastName(lastName); patient1.setFirstName(firstName); patients
[patientCntr] = patient 1 ; patientCntr+t; } return patient1; /** * Returns Patient from the array /
@override public Patient getPatient(UUID patientId) { for (Patient patient : patients) {
if(patient != null && patient.getPatientId().equals(patientId)) { return patient; } } } return
null; / * Retrieves Patient/Disease from the * respective arrays */ @override public void
addDiseaseToPatient(UUID patientId, UUID diseaseId) { Patient patient 2 = getPatient
(patientId); Disease disease2 = getDisease ( diseaseId ); if (patient2 != null && disease2 !=
null){ } patient2.addDiseaseId(disease2.getDiseaseId()); } / * Retrieve Patient from pateints
array */ @override public void addExposureToPatient(UUID patientId, Exposure exposure) {
Patient patient3 = getPatient ( patientId); if (patient 3!= null) { } patient3.addExposure
(exposure); } / * Gets the disease array * (i)return */ public Disease[] getDiseases() { return
diseases; } / * Gets the patient array * (ireturn / public Patient [] getPatients() { return patients;
} / * Calls the init method on the * DiseasefileRepository implementation. */ public void
init(String folderPath) { DiseaseAndPatient data = null; try { data = fileRep.init () ; } catch
(IOException | ClassNotFoundexception e) { // TODO Auto-generated catch block
e.printStackTrace(); } this .diseases = data.getDiseases () ; } this. patients = data.getPatients () ;
/ * Calls the save method on the * DiseasefileRepository implementation
package edu.disease.asn3; import static org.junit.Assert.*; import static org.junit.
Assert.assertThrows; import org.junit.After; import org.junit.Before; import org.junit.Test;
import java.io.file; import java.nio.file.Path; import java.util.UUID; public class
DiseaseControlManagerImplTest { public DiseaseControlManagerImpl manager; private static
final String testFolder = "test"; @Before public void setUp() { manager = new
DiseaseControlManagerImpl (10,10); } (iAfter public void folderClean() { File test = new
File(testFolder); if (test.exists ()) { String[] files = test.list(); for (String file : files) (f) } new
File(test, file).delete(); test.delete(); } } @Test public void testAddDisease() { Disease
disease1 = manager.addDisease ("Covide-19", true); assertNotNull (disease1);
assertEquals("COVID-19", disease1.getName()); assertTrue(disease1 instanceof
InfectiousDisease); Disease disease2 = manager.addDisease("Cardiovascular Disease", false);
assertNotNull (disease2); assertEquals("Cardiovascular Disease", disease2.getName());
assertTrue(disease2 instanceof NonInfectiousDisease); }
assertThrows(IllegalstateException.class, () -> manager.addDisease(" ", true)); @Test public
void testGetDisease() { Disease disease1 = manager.addDisease ("Influenza", true); UUID
diseaseId = diseasel.getDiseaseId(); Disease retrievedDisease = manager .getDisease ( diseaseId
); assertNotNull (retrievedDisease); assertEquals(diseaseId, retrievedDisease.getDiseaseId()); }
assertEquals("Influenza", retrievedDisease.getName()); @Test public void testAddPatient() {
Patient patient1 = manager.addPatient("Morgan", "Joe", 5, 10); assertNotNull (patient1);
assertEquals("Morgan", patient1.getLastName()); assertEquals("Joe", patient1.getFirstName());
} assertThrows(IllegalStateException.class, () -> manager.addPatient(" ", " ", 0, 0)); @Test
public void testGetPatient() { Patient patient1 = manager. addPatient ("Bench", "Johnny", 3, 7);
UUID patientId = patient1.getPatientId(); Patient retrievedPatient = manager .getPatient (
patientId ); assertNotNull (retrievedPatient); assertEquals (patientId,
retrievedPatient.getPatientId()); assertEquals("Bench", retrievedPatient.getLastName());
assertEquals("Johnny", retrievedPatient.getFirstName()); } assertNull
(manager.getPatient(UUID. randomUUID()));
} assertNulL (manager getPatient(UUID. randomUUID())); @Test public void
testAddDiseaseToPatient() { Disease disease1 = manager. addDisease ("Malaria", true); Patient
patient1 = manager .addPatient ("Griffy", "Ken", 5, 10); UUID diseaseId = diseasel.getDiseaseId
(); UUID patientId = patient 1 .getPatientId (); manager. addDiseaseToPatient (patientId,
diseaseId); Patient retrievedPatient = manager getPatient (patientId);
assertNotNull(retrievedPatient); assertTrue (retrievedPatient.getDiseaseIds (). length >0);
assertEquals(diseaseId, retrievedPatient.getDiseaseIds()[0]); } @Test public void
testAddExposureToPatient() { Patient patient1 = manager.addPatient ("Rose", "Pete", 4, 8);
UUID patientId = patient 1 getPatientId () ; Exposure exposure = new Exposure( patientId);
manager.addExposureToPatient (patientId, exposure); Patient retrievedPatient = manager
getPatient ( patientId ); assertNotNull(retrievedPatient); assertTrue
(retrievedPatient.getExposures(). length > 0 ); assertEquals(exposure,
retrievedPatient.getExposures()[0]); } @Test public void testGetDiseases() { Disease disease1
= manager.addDisease ("Covid-19", true); Disease disease2 = manager. addDisease ("Common
cold", true); Disease [ ] diseases = manager getDiseases(); assertNotNull(diseases);
assertEquals(2, diseases.length); } @Test public void testGetPatients() { Patient p1 = manager
.addPatient ("Bench", "Johnny", 10, 10); Patient p2 = manager.addPatient ("Votto", "Joe", 10,
10); Patient [] patients = manager getPatients () ; assertNotNull (patients); } assertEquals(2,
patients.length); @Test public void testInitAndSave() throws Exception { String folderTest =
Path.of(testFolder ). toAbsolutePath (). toString (); manager.init(folderTest); Disease disease1 =
manager. addDisease ("CoVID-19", true); Disease disease2 = manager. addDisease ("Common
Cold", true); Patient patient1 = manager.addPatient ("Tony", "Perez", 10, 10); Patient patient2 =
manager.addPatient ("Ken", "Griffey", 10, 10); manager.save(); DiseaseControlManagerImpl
newManager = new DiseaseControlManagerImpl (10,10); newManager.init(folderTest);
Disease[] newD = newManager getDiseases (); Patient [] newP = newManager .getPatients ();
assertNotNull (newD); assertNotNull (newP); assertEquals(2, newD.length); } assertEquals(2,
newP.length); }

More Related Content

PDF
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
PDF
Define a class named Doctor whose objects are records for clinic’s d.pdf
PDF
package s3; Copy paste this Java Template and save it as Emer.pdf
PDF
Here is how the code works1. Patient.java is an Abstract Class whi.pdf
PDF
Need help with this Java practice project. Im brand new to coding s.pdf
PDF
Hello. Im creating a class called Bill. I need to design the class.pdf
PDF
In Java- Create a Graduate class derived from Student- A graduate has.pdf
PDF
Tested on EclipseBoth class should be in same package.pdf
Sorting Questions (JAVA)See attached classes below.Attached Clas.pdf
Define a class named Doctor whose objects are records for clinic’s d.pdf
package s3; Copy paste this Java Template and save it as Emer.pdf
Here is how the code works1. Patient.java is an Abstract Class whi.pdf
Need help with this Java practice project. Im brand new to coding s.pdf
Hello. Im creating a class called Bill. I need to design the class.pdf
In Java- Create a Graduate class derived from Student- A graduate has.pdf
Tested on EclipseBoth class should be in same package.pdf

Similar to Ive already completed the Java assignment below, but it doesnt wor.pdf (20)

PDF
How to fix these erros The method sortListltTgt in the.pdf
PDF
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
PDF
public class Patient extends Person {=========== Properties ====.pdf
DOCX
cs320_final_project_codemedicalApplication.classpathcs320_.docx
PPT
3 j unit
PDF
29. Code an application program that keeps track of student informat.pdf
PPTX
class object.pptx
PPT
Chapter 7 - Defining Your Own Classes - Part II
PDF
public class Person { private String name; private int age;.pdf
PPT
Java căn bản - Chapter7
PDF
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
PDF
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
PDF
[10] Write a Java application which first reads data from the phoneb.pdf
PDF
Introducing generic types
PPT
Java Concepts
PDF
Patient.java package A9.toStudents; public class Patient imple.pdf
PPTX
Android Training (Storing & Shared Preferences)
PDF
In this project you will define some interfaces, abstract classes, a.pdf
PPT
Struggling to Create Maintainable Unit Tests?
PDF
URGENTJavaPlease updated the already existing Java program and m.pdf
How to fix these erros The method sortListltTgt in the.pdf
Adapt your code from Assignment 2 to use both a Java API ArrayList a.pdf
public class Patient extends Person {=========== Properties ====.pdf
cs320_final_project_codemedicalApplication.classpathcs320_.docx
3 j unit
29. Code an application program that keeps track of student informat.pdf
class object.pptx
Chapter 7 - Defining Your Own Classes - Part II
public class Person { private String name; private int age;.pdf
Java căn bản - Chapter7
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
[10] Write a Java application which first reads data from the phoneb.pdf
Introducing generic types
Java Concepts
Patient.java package A9.toStudents; public class Patient imple.pdf
Android Training (Storing & Shared Preferences)
In this project you will define some interfaces, abstract classes, a.pdf
Struggling to Create Maintainable Unit Tests?
URGENTJavaPlease updated the already existing Java program and m.pdf
Ad

More from fantasiatheoutofthef (20)

PDF
Introduction Pervasive computing demands the all-encompassing exploi.pdf
PDF
International projects are on the rise, so the need for project mana.pdf
PDF
Instructions On July 1, a petty cash fund was established for $100. .pdf
PDF
Just C, D, E 7-1 Hoare partition correctness The version of PART.pdf
PDF
Integral ICreate a Python function for I-Importancedef monteca.pdf
PDF
IntroductionThe capstone project is a �structured walkthrough� pen.pdf
PDF
Industry Solution Descartes for Ocean Carriers Customer Success Stor.pdf
PDF
Jefferson City has several capital projects that the mayor wants to .pdf
PDF
Instructions Create an Android app according to the requirements below.pdf
PDF
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
PDF
In this case study, we will explore the exercise of power in leaders.pdf
PDF
James Santelli was staying at a motel owned by Abu Rahmatullah for s.pdf
PDF
In this assignment you will implement insert() method for a singly l.pdf
PDF
Introduction Pervasive computing demands the all-encompassing exploita.pdf
PDF
Introduction (1 Mark)Body (7 Marks)1-Definition of Technolog.pdf
PDF
Integral IEstimator for Iwhere f(x) = 20 - x^2 and p(x) ~ U[a,.pdf
PDF
Indicate and provide a brief explanation for whether the following i.pdf
PDF
Lindsay was leaving a local department store when an armed security .pdf
PDF
Learning Team � Ethical Challenges Worksheet Your team of internat.pdf
PDF
Lecture Activity 7.1 Evaluating Evidence on Wikipedia Scenario You.pdf
Introduction Pervasive computing demands the all-encompassing exploi.pdf
International projects are on the rise, so the need for project mana.pdf
Instructions On July 1, a petty cash fund was established for $100. .pdf
Just C, D, E 7-1 Hoare partition correctness The version of PART.pdf
Integral ICreate a Python function for I-Importancedef monteca.pdf
IntroductionThe capstone project is a �structured walkthrough� pen.pdf
Industry Solution Descartes for Ocean Carriers Customer Success Stor.pdf
Jefferson City has several capital projects that the mayor wants to .pdf
Instructions Create an Android app according to the requirements below.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
In this case study, we will explore the exercise of power in leaders.pdf
James Santelli was staying at a motel owned by Abu Rahmatullah for s.pdf
In this assignment you will implement insert() method for a singly l.pdf
Introduction Pervasive computing demands the all-encompassing exploita.pdf
Introduction (1 Mark)Body (7 Marks)1-Definition of Technolog.pdf
Integral IEstimator for Iwhere f(x) = 20 - x^2 and p(x) ~ U[a,.pdf
Indicate and provide a brief explanation for whether the following i.pdf
Lindsay was leaving a local department store when an armed security .pdf
Learning Team � Ethical Challenges Worksheet Your team of internat.pdf
Lecture Activity 7.1 Evaluating Evidence on Wikipedia Scenario You.pdf
Ad

Recently uploaded (20)

PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Presentation on HIE in infants and its manifestations
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
GDM (1) (1).pptx small presentation for students
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Classroom Observation Tools for Teachers
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Anesthesia in Laparoscopic Surgery in India
Presentation on HIE in infants and its manifestations
A systematic review of self-coping strategies used by university students to ...
GDM (1) (1).pptx small presentation for students
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Institutional Correction lecture only . . .
Classroom Observation Tools for Teachers
O7-L3 Supply Chain Operations - ICLT Program
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

Ive already completed the Java assignment below, but it doesnt wor.pdf

  • 1. I've already completed the Java assignment below, but it doesn't work. I will include my code and the tests. Please correct my code and tests to that they match what has been asked and reached 95% test coverage as asked for in the assignment. Assignment: Disease File Repository This assignment is a continuation of the last assignment. Please use the Eclipse project that you created in the first assignment for this work. Source Code Class: Exposure Copy the Exposure class from the previous assignment into the new. Make the necessary changes so that this class can be serialized. Class: Patient Copy Patient class from the previous assignment into the new. Make the necessary changes so that this class can be serialized and that it uses the Exposure class class. Class: Disease Copy the Disease, the InfectiousDisease, the NonInfectiousDisease classes from the previous assignment into the new. Make the necessary changes so that they can be serialized. Class: DiseaseAndPatient Create a class called DiseaseAndPatient and define the follwing properties: private Disease[] diseases; private Patients[] patients; Create getter and setter methods for the two arrays and document the new methods using the Javadoc standard.
  • 2. Class: DiseaseFileRepository Create a class called DiseaseFileRepository and define the following methods: DiseaseAndPatient init(String folderPath) This method accepts a file path to the folder where the data was serialiaed and set the folder path to a propert on this class. Deserialize the disease data from the file named diseases.dat. Deserialize the patient data from the file named patients.fat. Set both the deserialized disease and patient arrays to an instance of the DiseaseAndPatient class and return that instance. Throw an IllegalArgumentException with an appropriate message if the supplied folder path is null. void save(Disease[] diseases, Patient[] patients) This method serializes and saves the supplied disease and patient array data to two separate files on the file system using the folder path from the init method. Serialize the disease array data to a file named disease.dat and the patient array data to the file name patients.dat. Documentation You are required to document the class, constructor, and methods using Javadoc standard. Class: DiseaseFileRepositoryTest Create a class called DiseaseFileRepositoryTest to test your DiseaseFileRespository class. You must achieve at least 95% test coverage on the DiseaseFileRepository class. Class: DiseaseControlManager and DiseaseControlManagerImpl Copy the DiseaseControlManager interface and the DiseaseControlMangerImpl class from the previous assignment and into the new. The DiseaseControlManager implementation will use the DiseaseFileRepository class that you created in this assignment to initialize and save the disease and patient data. Constructor
  • 3. Add a DiseaseFileRepository property to the DiseaseControlManager implementation and initialize the property in the constructor of the Disease ControlManager implementation. Additional Methods Add below methods to the DiseaseControlManager interface and implement the methods in the DiseaseControlManagerImpl class: Disease[] getDisease() package edu.disease.asn3; public class NonInfectiousDisease extends Disease{ /** Creates a string array containing four nonifectctious, examples * of diseases / @override public String[] getExamples() { return new String[] { "Cardiovascular Disease", "Diabetes", "Cystic Fibrosis", "Hypertension"}; } /** * Creates a string array containing * four nonifectctious examples * of diseases */ @override public String[] getExamples() { return new String[] {"Cardiovascular Disease", "Diabetes", "Cystic Fibrosis", "Hypertension"}; } }
  • 4. */ public abstract class Disease implements Serializable{ /** Properties specified in assignment */ UUID diseaseId; String name; /** Setter for diseaseId (1param diseaseId */ public void setDiseaseId(UUID diseaseId) { this. diseaseId = diseaseId; } /** Getter for diseaseID (ireturn */ public UUID getDiseaseId() { return diseaseId; } /** Setter for name (iparam name */ public void setName(String name) { this. name = name; } /** Getter for name (i)return */ public String getName() { return name; } @Override public int hashCode() { return objects.hash(diseaseId); } @Override public boolean equals(object obj) { if (this ==obj ) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Disease other = (Disease) obj; return objects.equals(diseaseId, other.disease } @override public String tostring() { return "Disease [diseaseId =" + diseaseId + ", } public abstract String[] getExamples(); /** Uses compareTo to sort patient by last name, then first name. The class compares the name of the patient, compares it to the last name of another patient, then sorts it. If the last names are the same, the first names are then compared to each other and sorted based on that. public int compareTo(Patient name) { int lastNameComp = this.lastName.compareToIgnoreCase(name. lastName); if (lastNameComp !=0){ return lastNameComp; else { return this.firstName.compareToIgnoreCase (name.firstName); / * Uses compareTo to sort patient by last name, then first name. The class * compares the name of the patient, compares it to the last name of another * patient, then sorts it. If the last names are the same, the first names * are then compared to each other and sorted based on that. */ public int compareTo(Patient name) { int lastNameComp = this. lastName. compareToIgnoreCase (name. lastName); if (lastNameComp !=0 ) { return lastNameComp; } else { return this.firstName.compareToIgnoreCase(name.firstName); } } }
  • 5. package edu.disease.asn3; import java.util.UUID; oublic interface DiseaseControlManager { / * Method adds a disease to the application. * @param name * @param infectious * @return */ public Disease addDisease(String name, boolean infectious); / * Gets a disease * @param diseaseId * Qreturn */ public Disease getDisease(UUID diseaseId); / * Adds a patient * @param firstName * @param lastName * @param maxDiseases * @param maxExposures * @return */ public Patient addPatient(String firstName, String lastName, int maxDiseases, int maxexposures); / * Gets a patient * @param patientId * @return */ public Patient getPatient(UUID patientId); / * Connects a disease to a patient * @param patientId * @param diseaseId */ public void addDiseaseToPatient(UUID patientId, UUID diseaseId); / * Connects exposure status to a patient * @param patientId * @param exposure */ public void addExposureToPatient(UUID patientId, Exposure exposure); / * Gets the disease array * @return */ public Disease[] getDiseases(); / * Gets the patient array * @return *I public Patient[] getPatients(); / * Calls the init method on the * DiseasefileRepository implementation. * Eparam folderPath */ public void init(String folderPath); /** * Calls the save method on the * DiseasefileRepository implementation * @throws Exception */ public void save() throws Exception; * Represents the patient by name and ID; includes exposures to * diseases and disease IDs. * (1)author * / public class Patient implements Serializable{ /** Properties as specified in assignment */ UUID patientId; String firstName; String lastName; Exposure[] exposures; UUID[] diseaseIds; /** Constructor for maxDiseases/maxExposures w/ Exception * @param maxDiseases * eparam maxExposures */ public Patient(int maxDiseases, int maxExposures) { if (maxDiseases <=0 maxExposures <=0 ) { } throw new IllegalArgumentException("Invaild input. "); this. diseaseIds = new UUID[maxDiseases]; this. exposures = new Exposure[maxDiseases ]; } /** Method for Disease array; adds diseaseId to array * (iparam diseaseId */ public void addDiseaseId(UUID diseaseId) { for (int i=0; i< diseaseIds.length; i++ ) { if (diseaseIds[i] == null) { diseaseIds [i]= diseaseId; return; } } } throw new IndexOutofBoundsException("Index is full."); /** Method of Exposure array * eparam exposure */ public void addExposure(Exposure exposure) { for (int i=0; i< exposures.length; i++ ) { if (exposures[i] == null) { exposures [i]= exposure; return; } } } throw new IndexOutofBoundsException("Index is full."); /** Setter for patientID * @iparam patientID */ public void setPatientId(UUID patientID) { this. patientId = patientID; } /** Getter for patientID * @ireturn */ public UUID getPatientId() { return patientId; } package edu.disease.asn3; import java.io.*; import java.nio.file.Paths; / * This class is includes methods for * creating and saving information for * the disease and patients arrays in * the
  • 6. DiseaseAndPatient class. */ public class DiseasefileRepository { / * Serialization is when a object is converted to a series * or sequence of bytes. The bytes include information about * the object's data type. This information can then be written * into a file. Desecialization is the reverse process and the * objects information can then be read from that file. * The private static final long property called serialversionUID * is written so that the user can make make changes as they wish * without relying on the system to generate one and then matching * the ID against multiple classes. * @param folderPath * @return */ private static String folderPath = "path"; / * Constructor that initializes * with folder path. * eparam folderPath */ public DiseasefileRepository() { if (folderPath == null) { } throw new IllegalArgumentException("Error: Folder path is null."); } this. folderPath = folderPath; / * This method serializes * disease information. * @param diseases * @throws FileNotFoundException * @throws IOException / public void serializeDiseases(Disease[] diseases) throws FileNotFoundException, IOException { try (FileoutputStream fout = new FileOutputStream(Paths.get(folderPath, "disease.dat").toString ()); ObjectOutputStream out = new ObjectOutputStream(fout)) { } out.writeobject(diseases); } / * This method desecializes * disease information. * @return * @throws FileNotFoundException * @throws IOException * @throws ClassNotFoundException */ public Disease[] deserializeDiseases() throws FileNotFoundException, IOException, ClassNotFoundException { try (FileInputStream fIn= new FileInputStream(Paths.get(folderPath, "diseases.dat"). toString ()); objectInputStream in = new objectInputStream (fIn)){ } return (Disease[]) in.readobject(); } / * This method serializes * patient information. * @param patients * @throws FileNotFoundException * @throws IOException */ public void serializePatients(Patient[] patients) throws FileNotFoundException, IoException { try (FileoutputStream fout = new FileOutputStream(Paths.get(folderPath, "patients.dat").toString ()); ObjectOutputStream out = new ObjectOutputStream(fout)) { } out.writeobject(patients); } package edu.disease.asn3; import static org.junit.Assert.assertEquals; import static org.junit. Assert.assertNotNull; import static org.junit. Assert.assertThrows; import static org.junit. Assert.assertTrue; import java.io.FileNotFoundException; import java.io.IoException; import org.junit.Before; import org.junit.Test; public class DiseaseFileRepositoryTest { private DiseaseFileRepository path; @Before public void setUp() { path = new DiseaseFileRepository (); } @Test public void testSaveAndInit() throws FileNotFoundException, IOException, ClassNotFoundException { Disease[] diseases = new Disease[2]; Patient [] patients = new Patient [2]; path.save(diseases, patients); DiseaseAndPatient data = path init(); Disease[] allDiseases = data.getDiseases () ; Patient[] allPatients = data.getPatients (); assertNotNull(allDiseases); assertNotNull(allPatients); assertEquals(2, alldiseases.length);
  • 7. assertEquals(2, allpatients.length); } public void nullFolderTest() { DiseaseFileRepository rep= new DiseaseFileRepository () ; assertThrows(FileNotFoundException.class, () -> rep.init()); } package edu.disease.asn3; public class InfectiousDisease extends Disease{ / * Creates a string array containing four examples of * infectious diseases. */ @override public String[] getExamples() { } return new String[]{"CoVID-19", "Common Cold", "Influenza", "Gastroenteritis"}; } public UUID getPatientId() { return patientId; } /** Setter for firstName * Qparam firstiname */ public void setFirstName(String firstName) { this.firstName = firstName; } /** Getter for firstName * @return */ public String getFirstName() { return firstName; } /** Setter for lastName * Qparam lastName */ public void setLastName(String lastName) { this.lastName = lastName; } /** Getter for lastName * @ireturn / public String getLastName() { return lastName; } / * Getter for Exposures */ public Exposure[] getExposures() { return exposures; } / * Setter for Exposure */ public void setExposures(Exposure[] exsposures) { this. exposures = exposures; } / * Setter for UUID */ public void setDiseaseIds(UUID[] diseaseIds) { this.diseaseIds = diseaseIds; } *** * Getter for UUID / public UUID[] getDiseaseIds() { return diseaseIds; } @override public int hashCode() { return objects.hash(patientId); } @override public boolean equals(object obj) { if (this ==obj ) return true; if (obj == null) return false; if (getClass() ! = obj.getClass()) return false; Patient other = (Patient) obj; } return objects.equals (patientId, other.patientId); @override public String tostring() { return "Patient [patientId=" + patientId + ", firstName=" + firstName + ", lastName=" + lastName + ", exposures=" + Arrays.toString(exposures) + ", diseaseIds=" + Arrays.toString(diseaseIds) + "]"; } / import java.util.objects; import java.util.UUID; import java.time.LocalDateTime; import java.io.Serializable; * Represents patient via ID, local time/date infomation, and exposure type * @author| / public class Exposure implements Serializable{ /** Properties as specified in the assignment / private UUID patientID; private LocalDateTime dateTime; private String exposureType; / Constructor for patientID * (iparam patientID */ public Exposure(UUID patientID) { this. patientID = patientID; } /**Setter for patientID * (iparam patientID */ public void setPatientID(UUID patientID) { this. patientID = patientID; } /** Getter for patientID * (ireturn / public UUID getPatientID() { return patientID; } /** Setter for dateTime * (jparam dateTime */ public void setDateTime(LocalDateTime dateTime) { this.dateTime = dateTime; } /** Getter for datTime * (ireturn */ public LocalDateTime getDateTime() { return dateTime; } / Setter for Exposure type * @param exposuretype */ public void setExposureType(String exposureType) { if (exposureType.equals("D") || exposureType.equals("I")) { this.
  • 8. exposureType = exposureType; } else { throw new IllegalArgumentException("Incorrect input. Input either 'D' for direct exposure or 'I' for indirect."); } } /** Getter for Exposure Type * @ireturn / public String getExposureType () { return exposureType; } /** Hash and equals as described in assignemtn */ @Override package edu.disease.asn3; import java.io.FileNotFoundException; [. public class DiseaseControlManagerImpl implements DiseaseControlManager { private Disease[] diseases; private Patient [] patients; int maxDiseases; int maxPatients; int diseaseCntr; int patientCntr; DiseasefileRepository fileRep; / * Constructor that accepts max diseases and max * patients that can be stored/initialize arrays * @param maxDiseases * @param folderPath * @param maxPatientss */ public DiseaseControlManagerImpl(int maxDiseases, int maxPatients) { if (maxDiseases < 0 maxPatients < ) { } throw new IllegalArgumentException("Error"); this maxDiseases = maxDiseases; this.maxPatients = maxPatients; this. diseases = new Disease [maxDiseases]; this.patients = new Patient [maxPatients]; this. diseaseCntr =0; this. patientCntr =0; } this.fileRep = new DiseasefileRepository (); / * Creates a new Disease and stores it * in the diseases array. Also, creates instance of * a Disease subclass. */ @override public Disease addDisease(String name, boolean infectious) { if (diseaseCntr >= maxDiseases) { } throw new IllegalstateException("Error"); Disease disease; if (infectious == false) { } disease = new NonInfectiousDisease () ; else { } disease = new InfectiousDisease (); disease.setName (name); disease. setDiseaseId(UUID. randomUUID()); new InfectiousDisease(); diseases [diseaseCntr] = disease; diseaseCntr++; } return disease; / * Returns Disease from the array */ @override public Disease getDisease(UUID diseaseId) { for(Disease disease : diseases) { if(disease != null && disease.getDiseaseId().equals(diseaseId)) { return disease; } } return null; } / * Creates a new Paitent using arugments and * adds them to the patients array. */ @Override public Patient addPatient(String lastName, String firstName, int maxDiseases, int maxEx if (patientCntr >= maxPatients) { throw new IllegalstateException("Error"); @Override public int hashCode() { return objects.hash(dateTime, patientID); } @override public boolean equals(object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Exposure other = (Exposure) obj; } return objects.equals(dateTime, other.dateTime) && objects.equals(patientID, other.patientID); / tostring as described in assignment */ @override public String tostring() { return "Exposure [patientID=" + patientID + ", dateTime=" + dateTime + ", exposureType=" + exposureType + "]"; } package edu.disease.asn3; public class DiseaseAndPatient { / * Properties as specified in the *
  • 9. assignement details. */ private Disease[] diseases; private Patient[] patients; / * Setter for the Disease array * eparam diseases * / public void setDiseases(Disease[] diseases) { this. diseases = diseases; } / * Getter for the Disease array * ereturn */ public Disease[] getDiseases() { return diseases; } / * Setter for the Patients array * eparam patients */ public void setPatients(Patient[] patients) { this. patients = patients; } / * Getter for the Patietns array * ereturn */ public Patient[] getPatients() { return patients; } } } / * Deserializes patient * information. * * @return * @throws FileNotFoundException * @throws IOException * @throws ClassNotFoundException */ public Patient[] deserializePatients() throws FileNotFoundException, IoException, ClassNotFoundException try (FileInputStream fIn = new FileInputStream(Paths.get(folderPath, "patients.dat").toString()); ObjectInputstream in = new ObjectInputStream(fIn)) { return (Patient []) in.readobject(); } } / * Uses previous methods to deserialize. * disease and patient data from the * disease.dat and patient.dat files. * * @return * @throws IOException * @throws ClassNotFoundException * @throws FileNotFoundException / public DiseaseAndPatient init() throws FileNotFoundException, ClassNotFoundException, IoException { Disease[] diseases = deserializeDiseases (); Patient [] patients = deserializePatients (); return new DiseaseAndPatient(); } / * Serializes information disease and * patient data from the disease.dat * and patient.dat files using methods * above. * * @param diseases * @param patients * @throws FileNotFoundException * @throws IOException */ public void save(Disease[] diseases, Patient[] patients) throws FileNotFoundException, IoException { serializeDiseases(diseases); serializePatients (patients); } } Patient patient1 = new Patient(maxDiseases, maxExposures); patient1. setPatientId(UUID. randomUUID ()); patient1.setLastName(lastName); patient1.setFirstName(firstName); patients [patientCntr] = patient 1 ; patientCntr+t; } return patient1; /** * Returns Patient from the array / @override public Patient getPatient(UUID patientId) { for (Patient patient : patients) { if(patient != null && patient.getPatientId().equals(patientId)) { return patient; } } } return null; / * Retrieves Patient/Disease from the * respective arrays */ @override public void addDiseaseToPatient(UUID patientId, UUID diseaseId) { Patient patient 2 = getPatient (patientId); Disease disease2 = getDisease ( diseaseId ); if (patient2 != null && disease2 != null){ } patient2.addDiseaseId(disease2.getDiseaseId()); } / * Retrieve Patient from pateints array */ @override public void addExposureToPatient(UUID patientId, Exposure exposure) { Patient patient3 = getPatient ( patientId); if (patient 3!= null) { } patient3.addExposure (exposure); } / * Gets the disease array * (i)return */ public Disease[] getDiseases() { return diseases; } / * Gets the patient array * (ireturn / public Patient [] getPatients() { return patients;
  • 10. } / * Calls the init method on the * DiseasefileRepository implementation. */ public void init(String folderPath) { DiseaseAndPatient data = null; try { data = fileRep.init () ; } catch (IOException | ClassNotFoundexception e) { // TODO Auto-generated catch block e.printStackTrace(); } this .diseases = data.getDiseases () ; } this. patients = data.getPatients () ; / * Calls the save method on the * DiseasefileRepository implementation package edu.disease.asn3; import static org.junit.Assert.*; import static org.junit. Assert.assertThrows; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.io.file; import java.nio.file.Path; import java.util.UUID; public class DiseaseControlManagerImplTest { public DiseaseControlManagerImpl manager; private static final String testFolder = "test"; @Before public void setUp() { manager = new DiseaseControlManagerImpl (10,10); } (iAfter public void folderClean() { File test = new File(testFolder); if (test.exists ()) { String[] files = test.list(); for (String file : files) (f) } new File(test, file).delete(); test.delete(); } } @Test public void testAddDisease() { Disease disease1 = manager.addDisease ("Covide-19", true); assertNotNull (disease1); assertEquals("COVID-19", disease1.getName()); assertTrue(disease1 instanceof InfectiousDisease); Disease disease2 = manager.addDisease("Cardiovascular Disease", false); assertNotNull (disease2); assertEquals("Cardiovascular Disease", disease2.getName()); assertTrue(disease2 instanceof NonInfectiousDisease); } assertThrows(IllegalstateException.class, () -> manager.addDisease(" ", true)); @Test public void testGetDisease() { Disease disease1 = manager.addDisease ("Influenza", true); UUID diseaseId = diseasel.getDiseaseId(); Disease retrievedDisease = manager .getDisease ( diseaseId ); assertNotNull (retrievedDisease); assertEquals(diseaseId, retrievedDisease.getDiseaseId()); } assertEquals("Influenza", retrievedDisease.getName()); @Test public void testAddPatient() { Patient patient1 = manager.addPatient("Morgan", "Joe", 5, 10); assertNotNull (patient1); assertEquals("Morgan", patient1.getLastName()); assertEquals("Joe", patient1.getFirstName()); } assertThrows(IllegalStateException.class, () -> manager.addPatient(" ", " ", 0, 0)); @Test public void testGetPatient() { Patient patient1 = manager. addPatient ("Bench", "Johnny", 3, 7); UUID patientId = patient1.getPatientId(); Patient retrievedPatient = manager .getPatient ( patientId ); assertNotNull (retrievedPatient); assertEquals (patientId, retrievedPatient.getPatientId()); assertEquals("Bench", retrievedPatient.getLastName()); assertEquals("Johnny", retrievedPatient.getFirstName()); } assertNull (manager.getPatient(UUID. randomUUID())); } assertNulL (manager getPatient(UUID. randomUUID())); @Test public void testAddDiseaseToPatient() { Disease disease1 = manager. addDisease ("Malaria", true); Patient
  • 11. patient1 = manager .addPatient ("Griffy", "Ken", 5, 10); UUID diseaseId = diseasel.getDiseaseId (); UUID patientId = patient 1 .getPatientId (); manager. addDiseaseToPatient (patientId, diseaseId); Patient retrievedPatient = manager getPatient (patientId); assertNotNull(retrievedPatient); assertTrue (retrievedPatient.getDiseaseIds (). length >0); assertEquals(diseaseId, retrievedPatient.getDiseaseIds()[0]); } @Test public void testAddExposureToPatient() { Patient patient1 = manager.addPatient ("Rose", "Pete", 4, 8); UUID patientId = patient 1 getPatientId () ; Exposure exposure = new Exposure( patientId); manager.addExposureToPatient (patientId, exposure); Patient retrievedPatient = manager getPatient ( patientId ); assertNotNull(retrievedPatient); assertTrue (retrievedPatient.getExposures(). length > 0 ); assertEquals(exposure, retrievedPatient.getExposures()[0]); } @Test public void testGetDiseases() { Disease disease1 = manager.addDisease ("Covid-19", true); Disease disease2 = manager. addDisease ("Common cold", true); Disease [ ] diseases = manager getDiseases(); assertNotNull(diseases); assertEquals(2, diseases.length); } @Test public void testGetPatients() { Patient p1 = manager .addPatient ("Bench", "Johnny", 10, 10); Patient p2 = manager.addPatient ("Votto", "Joe", 10, 10); Patient [] patients = manager getPatients () ; assertNotNull (patients); } assertEquals(2, patients.length); @Test public void testInitAndSave() throws Exception { String folderTest = Path.of(testFolder ). toAbsolutePath (). toString (); manager.init(folderTest); Disease disease1 = manager. addDisease ("CoVID-19", true); Disease disease2 = manager. addDisease ("Common Cold", true); Patient patient1 = manager.addPatient ("Tony", "Perez", 10, 10); Patient patient2 = manager.addPatient ("Ken", "Griffey", 10, 10); manager.save(); DiseaseControlManagerImpl newManager = new DiseaseControlManagerImpl (10,10); newManager.init(folderTest); Disease[] newD = newManager getDiseases (); Patient [] newP = newManager .getPatients (); assertNotNull (newD); assertNotNull (newP); assertEquals(2, newD.length); } assertEquals(2, newP.length); }