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> rows = new ArrayList>(); // This variable is when we store our new data

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 newData = new ArrayList(); // variable to store the neww data in it if(data[2] != id) // When the third element is not equal to the given id we do not copy the row { for(String past:data) { newData.add(past); } rows.add(newData); // We add the copied row to the others } else { Patient w = new Patient (); // Here we construct a patient and we return the removed patient w.data = data; return w; } } csvReader.close(); // To close the opened file for (ArrayList rowData : rows) { // to copy data from the list to the csv file csvWriter.append(String.join(",", rowData)); csvWriter.append(" "); }

csvWriter.flush(); csvWriter.close();// to close the file written return null; } public void setResultForPatient (String id, String result) throws IOException { ArrayList> rows = new ArrayList>(); // This variable is when we store our new data

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 newData = new ArrayList(); // variable to store the neww data in it if(data[2] != id) // When the third element is not equal to the given id we do not copy the row { for(String past:data) { newData.add(past); } rows.add(newData); // We add the copied row to the others } else { String[] newwData = result.split(","); // split the information separated by comma for(String past:newwData) { newData.add(past); } rows.add(newData); // We add the copied row to the others } } csvReader.close(); // To close the opened file for (ArrayList rowData : rows) { // to copy data from the list to the csv file csvWriter.append(String.join(",", rowData)); csvWriter.append(" "); }

csvWriter.flush(); csvWriter.close();// to close the file written }

public ArrayList getIds () throws IOException { ArrayList result = new ArrayList(); // to store the list of ids for(int i=1;i

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 newData = new ArrayList(); // variable to store the neww data in it if(data.length == 4775 ) { output = output+" "+row+" "; for(String past:data) { newData.add(past); } csvWriter.append(String.join(",", newData)); csvWriter.append(" "); } else { output = output+" error in line "+rowNumber; } } csvReader.close(); // To close the opened file csvWriter.flush(); csvWriter.close();// to close the file written return output; }

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 getIds () throws IOException;

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.

}

 This java code takes a csv file and adds data from

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!