Question: This java code takes a csv file and adds data from it from various points in it. This code takes a csv file, and finds
This java code takes a csv file and adds data from it from various points in it. This code takes a csv file, and finds the first, third, 3697th, and the 3258th in that order.
How would I implement a mainclass that adds an ability to query the system getting identifiers, a patient, a prediction for a patient, etc.
There's an ADT class but it won't fit, if you need it I can get it to you
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
}
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.
}

Patientjava D TesterClassjava AceData Manager Patient 'Patientjava o "PatientCollec... 23 D 'tester jav 1 package project; 28 import java.io.FiletotFoundException; 6 public interface Patientcollection // TODO Auto-generated method stub public Patient getPatient (String id) throws IOException 11 Return the patient with the given id. Return void if the id does 17 not exist in the collection public patient removePatient (String id) throws toException; 11 Rebove and return the patient with the given id. Return void if the id does not exist. public void setResultfor Patient (String id, String result) throws IOException; // Set the result field for the patient with given id. public ArrayList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
