Question
This code takes a csv file and adds data from it from various points in it. How would I implement a tester class that would:
This code takes a csv file and adds data from it from various points in it. How would I implement a tester class that would:
- An ability to query the system getting identifiers, a patient, a prediction for a patient, etc.
- An ability to add, remove and maintain patients in the system
Would that be done in a tester class or would I need another backend class?
package project1;
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger;
public class Patient implements PatientCollectionADT{ String[] data; // Variable to store patient data Patient (){ // Patient constructor } public Patient getPatient(String id) throws IOException { Patient x; String row; // Variable of the csv file row BufferedReader csvReader = new BufferedReader(new FileReader("ourFile.csv")); // here we open our csv file and we replace "ourFile.csv" with our path while ((row = csvReader.readLine()) != null) { // To confirm that the file is not ended yet String[] data = row.split(","); // to split the row we red when we find a "," if(data[2] == id) // the third data is equal to the given id we construct a new patient with the information of this row and we return this patient { x = new Patient (); x.data = data; return x; } } csvReader.close(); // To close the opened file return null; } public Patient removePatient(String id) throws IOException{ ArrayList
FileWriter csvWriter = new FileWriter("data.csv");
String row; // Variable of the csv file row BufferedReader csvReader = new BufferedReader(new FileReader("ourFile.csv")); // here we open our csv file and we replace "ourFile.csv" with our path while ((row = csvReader.readLine()) != null) { // To confirm that the file is not ended yet String[] data = row.split(","); // to split the row we red when we find a "," ArrayList
csvWriter.flush(); csvWriter.close();// to close the file written return null; } public void setResultForPatient (String id, String result) throws IOException { ArrayList
FileWriter csvWriter = new FileWriter("ourFile.csv");
String row; // Variable of the csv file row BufferedReader csvReader = new BufferedReader(new FileReader("ourFile.csv")); // here we open our csv file and we replace "ourFile.csv" with our path while ((row = csvReader.readLine()) != null) { // To confirm that the file is not ended yet String[] data = row.split(","); // to split the row we red when we find a "," ArrayList
csvWriter.flush(); csvWriter.close();// to close the file written }
public ArrayList
public String addPatientsFromFile (String fileName) throws FileNotFoundException, IOException{
FileWriter csvWriter = new FileWriter("ourFile.csv"); String output = ""; // to store the printed output int rowNumber = 0; // to detect where the error is (row) String row; // Variable of the csv file row BufferedReader csvReader = new BufferedReader(new FileReader(fileName)); // here we open our csv file while ((row = csvReader.readLine()) != null) { // To confirm that the file is not ended yet rowNumber++; String[] data = row.split(","); // to split the row we red when we find a "," ArrayList
public String toString (){ String result =""; // to store the list of patients for(int i=1;i<=21;i++) { Patient x = new Patient(); try { x = getPatient(String.valueOf(i)); // get the patient with the id = i } catch (IOException ex) { Logger.getLogger(Patient.class.getName()).log(Level.SEVERE, null, ex); } result = result + x.data[3696]+" "+x.data[3257] + " "; // store the patient data } return result; }
}
package project1; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList;
public interface PatientCollectionADT {
// TODO Auto-generated method stub public Patient getPatient (String id) throws IOException;
// Return the patient with the given id. Return void if the id does
// not exist in the collection
public Patient removePatient (String id) throws IOException;
// Remove and return the Patient with the given id. Return void if the id does not exist.
public void setResultForPatient (String id, String result) throws IOException;
// Set the result field for the patient with given id.
public ArrayList
public String addPatientsFromFile (String fileName) throws FileNotFoundException, IOException;
// Each line must contain a unique patient identifier followed by exactly 4776 doubles.
// If the line does not meet the criteria, it is not added to the patient collection,
// and an error message is included in the return String.
// The error message will indicate which line was in error and what the error was.
// expected line format
//id,protein1,protein2, ... , protein4776
public String toString ();
// Return a String representation of the collection.
// Only include the 3697th and 3258th values in that order.
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started