Answered step by step
Verified Expert Solution
Link Copied!

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 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
Figure 2: Invoking Bank:AccountProcessor, and selecting NOT to continue after an error.
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.
Figure 3: Invoking BankAccountProcessor, and selecting to continue after an error this is my code pease help I have posted this question 5 times now and each time i am not getting the desired output this is my code 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){
// Create a Scanner object to read input from the user
Scanner scanner = new Scanner(System.in);
// 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.println("What file would you like to parse?");
String fileName = scanner.nextLine();
// Open a BufferedReader to read the contents of the file
BufferedReader reader = new BufferedReader(new FileReader(fileName));
String line;
// Read each line from the file until the end
while ((line = reader.readLine())!= null){
try {
// Process each line
processLine(line);
// Print a success message for successfully processed lines
System.out.println("Line "+ line +" successfully processed");
} catch (BankAccountException e){
// Handle the custom exception for invalid bank account info
System.out.println(e.getMessage());
// Ask the user if they want to continue parsing the file
System.out.println("Continue?(y/n)");
String response = scanner.nextLine();
// Check if the user wants to continue
if (!response.equalsIgnoreCase("y")){
// 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.println("File has been parsed.");
// Ask the user if they want to continue parsing more files
System.out.println("Continue?(y/n)");
String response = scanner.nextLine();
// Check if the user wants to continue
if (!response.equalsIgnoreCase("y")){
// 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.println("File not found:" + e.getMessage());
// Set runProgram to false to exit the loop
runProgram = false;
} catch (IOException e){
// Handle IO exception
System.out.println("Error reading file: "+ e.getMessage());
// Set runProgram to false to exit the loop
runProgram = false;
}
}
// Print a message indicating that the program is quitting
System.out.println("Okay, quitting");
// Close the Scanner object
scanner.close();
}
// Method to process each line from the file
private static void processLine(String line) throws BankAccountException {
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How does prolonged stress damage the hippocampus?

Answered: 1 week ago

Question

Explain budgetary Control

Answered: 1 week ago

Question

Solve the integral:

Answered: 1 week ago

Question

What is meant by Non-programmed decision?

Answered: 1 week ago

Question

What are the different techniques used in decision making?

Answered: 1 week ago