Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need this output What file would you like to parse. accountsFile.txt Line 7 5 3 6 7 6 5 4 9 0 ; Tatiana
I need this output 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:
Continue?
n
Okay, quitting
Figure : Invoking Bank:AccountProcessor, and selecting NOT to continue after an error.
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:
Continue?
y
Invalid Bank Account info : Invalid account number:
Continue?
y
File has been parsed.
Figure : Invoking BankAccountProcessor, and selecting to continue after an error this is my code pease help I have posted this question times now and each time i am not getting the desired output this is my code import java.ioBufferedReader;
import java.ioFileNotFoundException;
import java.ioFileReader;
import java.ioIOException;
import java.util.Scanner;
public class BankAccountProcessor
public static void mainString args
Create a Scanner object to read input from the user
Scanner scanner new ScannerSystemin;
Initialize a boolean variable to control the program flow
boolean runProgram true;
Start a while loop to keep the program running until user decides to quit
while runProgram
try
Ask the user for the file to parse
System.out.printlnWhat file would you like to parse?";
String fileName scanner.nextLine;
Open a BufferedReader to read the contents of the file
BufferedReader reader new BufferedReadernew FileReaderfileName;
String line;
Read each line from the file until the end
while line reader.readLine null
try
Process each line
processLineline;
Print a success message for successfully processed lines
System.out.printlnLine line successfully processed";
catch BankAccountException e
Handle the custom exception for invalid bank account info
System.out.printlnegetMessage;
Ask the user if they want to continue parsing the file
System.out.printlnContinueyn;
String response scanner.nextLine;
Check if the user wants to continue
if response.equalsIgnoreCasey
If the user does not want to continue, set runProgram to false to exit the loop
runProgram false;
break;
Close the BufferedReader after parsing the file
reader.close;
Check if the user wants to continue parsing files
if runProgram
If the user wants to continue, inform that the file has been parsed
System.out.printlnFile has been parsed.";
Ask the user if they want to continue parsing more files
System.out.printlnContinueyn;
String response scanner.nextLine;
Check if the user wants to continue
if response.equalsIgnoreCasey
If the user does not want to continue, set runProgram to false to exit the loop
runProgram false;
catch FileNotFoundException e
Handle the case where the file is not found
System.out.printlnFile not found:" egetMessage;
Set runProgram to false to exit the loop
runProgram false;
catch IOException e
Handle IO exception
System.out.printlnError reading file: egetMessage;
Set runProgram to false to exit the loop
runProgram false;
Print a message indicating that the program is quitting
System.out.printlnOkay quitting";
Close the Scanner object
scanner.close;
Method to process each line from the file
private static void processLineString line throws BankAccountException
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