Question: import java.io . BufferedReader; import java.io . FileNotFoundException; import java.io . FileReader; import java.io . IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; public class EV

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
public class EV03{
private static final int INITIAL_CAPACITY =10;
private static EVRecord[] data = new EVRecord[INITIAL_CAPACITY];
private static HashSet duplicates = new HashSet<>();
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("Enter the file path to read EV data");
String filePath = in.nextLine();
try (BufferedReader br = new BufferedReader(new FileReader(filePath))){
processFile(br);
} catch (FileNotFoundException e){
System.out.println("File is not found. Exiting from the program");
System.exit(1);
} catch (IOException e){
System.out.println("Input file has some problem. Exiting from the program");
System.exit(1);
}
}
private static void processFile(BufferedReader br) throws IOException {
String line;
int lineCount =0, count =0, duplicateCount =0, invalidCount =0;
String header = br.readLine();
while ((line = br.readLine())!= null){
lineCount++;
String[] columns = line.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)",-1);
if (!checkColumnLength(columns.length)){
System.out.println("Invalid data at line "+ lineCount +"- column length does not match.");
continue;
}
if (duplicates.contains(columns[0]+ columns[13])){
System.out.println("Duplicate at line "+ lineCount);
duplicateCount++;
} else {
boolean validCheck = validateColumns(columns);
if (!validCheck){
System.out.println("Invalid data at line "+ lineCount);
invalidCount++;
} else {
EVRecord newRecord = new EVRecord(columns);
if (count == data.length){
data = Arrays.copyOf(data, data.length *2);
}
data[count]= newRecord;
count++;
duplicates.add(newRecord.getRecordID());
}
}
}
System.out.println("recordID;"+ header.replaceAll(",",";"));
printReverse(count);
System.out.println("Data lines read:" + lineCount +" Records in memory: "+ count +" Invalid records: "+ invalidCount +" Duplicate records: "+ duplicateCount);
}
private static boolean checkColumnLength(int length){
return length ==17;
}
private static void printReverse(int count){
for (int i = count -1; i >=0; i--){
System.out.println(data[i]);
}
}
private static boolean validateColumns(String[] columns){
// Validation logic for columns
}
}package week2;
public class EVRecord {
private String attribute1;
private int attribute2;
// Add other attributes as needed
// Constructor with parameters
public EVRecord(String attribute1, int attribute2){
this.attribute1= attribute1;
this.attribute2= attribute2;
// Initialize other attributes if needed
}
// Accessor methods
public String getAttribute1(){
return attribute1;
}
public int getAttribute2(){
return attribute2;
}
// Mutator methods if needed
public void setAttribute1(String attribute1){
this.attribute1= attribute1;
}
public void setAttribute2(int attribute2){
this.attribute2= attribute2;
}
// toString method to print attributes with comma
@Override
public String toString(){
return attribute1+","+ attribute2;
// Add other attributes if needed
}
} fix these code

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!