Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can you fix the code so that it can display the correct output It need to display ( , ) comthing like this exaple two
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 ;Tatiana Harrison successfully processed
Line ;John Anvik successfully processed
Invalid Bank Account info : Account number has nondigit character: a
Continue?
n
Okay, quitting Example one
What file would you like to parse.
accountsFile.txt
Line ;Tatiana Harrison successfully processed
Line ;John Anvik successfully processed
Invalid Bank Account info : Account number has nondigit character: a
Continue?
y
Invalid Bank Account info : Invalid account number: f
Continue?
y
File has been parsed. file import java.ioBufferedReader;
import java.ioFileNotFoundException;
import java.ioFileReader;
import java.ioIOException;
import java.util.Scanner;
public class BankAccountProcessor
public static void mainString args
Scanner scanner new ScannerSystemin;
boolean runProgram true;
while runProgram
try
System.out.printlnWhat file would you like to parse?";
String fileName scanner.nextLine;
BufferedReader reader new BufferedReadernew FileReaderfileName;
String line;
while line reader.readLine null
try
processLineline;
catch BankAccountException e
System.out.printlnegetMessage;
System.out.printlnContinueyn;
String response scanner.nextLine;
if response.equalsIgnoreCasey
runProgram false;
break;
reader.close;
if runProgram
System.out.printlnFile has been parsed.";
System.out.printlnContinueyn;
String response scanner.nextLine;
if response.equalsIgnoreCasey
runProgram false;
catch FileNotFoundException e
System.out.printlnFile not found: egetMessage;
runProgram false;
catch IOException e
System.out.printlnError reading file: egetMessage;
runProgram false;
System.out.printlnOkay quitting";
scanner.close;
private static void processLineString line throws BankAccountException
String tokens line.split;;
if tokenslength
throw new BankAccountExceptionInvalid Bank Account info : Missing semicolon delimiter";
String accountNumber tokens;
String name tokens;
if accountNumberlength
throw new BankAccountExceptionInvalid Bank Account info : Account number length is not ;
if accountNumber.matchesd
throw new BankAccountExceptionInvalid Bank Account info : Account number has nondigit character: accountNumber;
if namelengthname.matchesazAZ
throw new BankAccountExceptionInvalid Bank Account info : Invalid name format";
System.out.printlnLine line successfully processed";
class BankAccountException extends Exception
public BankAccountExceptionString message
supermessage;
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 digit number
The person's name is composed of ONLY alphabetic characters andor the space, and
must be at least 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 For this
programming task, you will write a main routine that parses the input file, linebyline, and
throws an error a custom error class that you'll write if the format of the account or name for a
line in the file is invalid.
;Tatiana Harrison
a;Jim
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