Question: can you fix the code so that it can display the correct output It need to display comthing like this exaple two What file would

can you fix the code so that it can display the correct output It need to display comthing like this exaple two What file would you like to parse.
accountsFile.txt
Line 7536765490;Tatiana Harrison successfully processed
Line 7462887443;John Anvik successfully processed
Invalid Bank Account info : Account number has non-digit character: 984733122a
Continue?
n
Okay, quitting Example one
What file would you like to parse.
accountsFile.txt
Line 7536765490;Tatiana Harrison successfully processed
Line 7462887443;John Anvik successfully processed
Invalid Bank Account info : Account number has non-digit character: 984733122a
Continue?
y
Invalid Bank Account info : Invalid account number: 04712f643
Continue?
y
File has been parsed. file import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class BankAccountProcessor {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
boolean runProgram = true;
while (runProgram){
try {
System.out.println("What file would you like to parse?");
String fileName = scanner.nextLine();
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String line;
while ((line = reader.readLine())!= null){
try {
processLine(line);
} catch (BankAccountException e){
System.out.println(e.getMessage());
System.out.println("Continue?(y/n)");
String response = scanner.nextLine();
if (!response.equalsIgnoreCase("y")){
runProgram = false;
break;
}
}
}
reader.close();
if (runProgram){
System.out.println("File has been parsed.");
System.out.println("Continue?(y/n)");
String response = scanner.nextLine();
if (!response.equalsIgnoreCase("y")){
runProgram = false;
}
}
} catch (FileNotFoundException e){
System.out.println("File not found: "+ e.getMessage());
runProgram = false;
} catch (IOException e){
System.out.println("Error reading file: "+ e.getMessage());
runProgram = false;
}
}
System.out.println("Okay, quitting");
scanner.close();
}
private static void processLine(String line) throws BankAccountException {
String[] tokens = line.split(";");
if (tokens.length !=2){
throw new BankAccountException("Invalid Bank Account info : Missing semicolon delimiter");
}
String accountNumber = tokens[0];
String name = tokens[1];
if (accountNumber.length()!=10){
throw new BankAccountException("Invalid Bank Account info : Account number length is not 10");
}
if (!accountNumber.matches("\\d+")){
throw new BankAccountException("Invalid Bank Account info : Account number has non-digit character: "+ accountNumber);
}
if (name.length()<3||!name.matches("[a-zA-Z ]+")){
throw new BankAccountException("Invalid Bank Account info : Invalid name format");
}
System.out.println("Line "+ line +" successfully processed");
}
}
class BankAccountException extends Exception {
public BankAccountException(String message){
super(message);
}
} For this task, you'll practice writing your own exception class. Assume that you have been asked
to write a program that parses a file with bank account data. Each line of the file contains a
number, corresponding to a bank account, followed by a semicolon, followed by a person's name.
The correct format is the following:
The bank account number is a 10 digit number
The person's name is composed of ONLY alphabetic characters and/or the space, and
must be at least 3 characters long
A sample input text file, which has multiple invalid entries, is provided for you on the course
website. A portion of that file (showing two of the errors in grey) is shown in Figure 1. For this
programming task, you will write a main routine that parses the input file, line-by-line, and 7536765490;Tatiana Harrison
984733122a;Jim Schwing
7462887443;John Anvik
04712f643;Razvan Andonie
9285373798;Herminia Mcshane
4398275022;Artie Baucom
2390213786;Katrice Heitkamp

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!