Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BankAccountException.java 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

BankAccountException.java

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 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.

image text in transcribed

To complete this programming task, write a program, BankAccountProcessor.java, that:

Has a main routine which:

Throws a FileNotFoundException

Prompts the user to input a file name

Sets a boolean sentinel value, runProgram, to true

Contains a while loop that continues while runProgram is set to true

The while loop code block contains a try-catch statement. The try block retrieves each line from the input file, and invokes the isValid method (see below), passing to it the line from the file. If there are no more lines to parse, runProgram is set to false, the while loop completes, and the entire program terminates

The catch statement catches a BankAccountException. When caught, the program prompts if the user wishes to continue, or quit the program.

Has an isValid method that:

Has the following signature

image text in transcribed

Uses a StringTokenizer to check if the account line conforms to the correct format:

Contains two tokens, with a semicolon delimiter o The first token is made up of 10 digits

The second token is made up of all alphabetic chars and/or an empty space, and is at least 3 characters long

If any of the checks for the line format fail, then an error of type

BankAccountException should be thrown

You'll need to write your own error class, BankAccountException, that extends Exception. The class should have a single constructor that takes a single argument, of type String, and which ONLY invokes its superclass's constructor.

Test your program, using the accountsFile.txt file that has been posted on the course website. There are several errors in that file, which your program should catch. When you program catches an error, it should exhibit behavior similar to what is shown in Figures 2 and 3. Namely:

When a line contains no errors, a successfully processed message should be posted. The program should not halt.

When a line contains an error, your program should stop, and prompt the user to continue.

image text in transcribed

Begin BankAccountException.java

// File: BankAccountException.java

// Description: VERY Simple custom Error class, that extends Exception

public class BankAccountException extends Exception {

public BankAccountException(String error) { super("Invalid Bank Account info : " + error); } }

End BankAccountException.java

begin AccountsFile.txt

7536765490;Tatiana Harrison 984733122a;Jim Schwing 7462887443;John Anvik 04712f643;Razvan Andonie 9285373798;Herminia Mcshane 4398275022;Artie Baucom 2390213786;Katrice Heitkamp 5011284575;Latonia Massi 9285273798;Sanjuanita Hemenway 4398275022;Brandee Lytch 2390213786;Amee Millikin 5011284575;Makeda Ballou 5360054175;Leighann Vivanco 9377110680;Una Randles 6106365199;Kaitlyn Sesco 3025912635;Ellan Dolin 2646078876;Alfonzo Luff 1303762828;Phillis Wernick 9003110134;Phillis Wernick 9338049111;Tonda Clem 2935054462;Sadye Brindley 9918775178;Christin Campos 2809054115;Aleisha Wing 4004534404;Meryl Maul 6859467081;Roselia Horstman 3179145807;Richie Rech 1087377713;Evon Eckman 8197144372;Roselia Horstman 7704844171;Lily Linquist 7366545555;Evon Eckman 1240560421;Elinore Echols 1041129232;Roselia Horstman 1176223044;Terrell Taub 3030983911;Maida Mohler 4190772334;Hong Heindel 4865779980;Kirk Koren 9356334215;Irena Imler 1146140236;Lawana Lemaster 6985561865;Sadye Brindley 4985293931;Jackeline Jolin 6013363403;Sadye Brindley 6453133104;Trista Twiss 4444846350;Alva Ankrom 6073684588;Nathalie Nuss 2128995368;Sadye Brindley 5475929290;Hai Harney 6006429204;Meryl Maul 4238692363;Else Esquivel 6365923944;Hong Heindel 6878255179;Olympia Ortego 4117259728;Beckie Brinkerhoff 4188632986;Jeannette Jantzen 5921203334;Leda Langone 8940597235;Meryl Maul 1301954781;Wilson Winter 7440881546;Jeannette Jantzen 3032857101;Meryl Maul 9285373798;Herminia Mcshane 4398275022;Artie Baucom 2390213786;Katrice Heitkamp 5011284575;Latonia Massi 9285273798;Sanjuanita Hemenway 4398275022;Brandee Lytch 2390213786;Amee Millikin 5011284575;Makeda Ballou 5360054175;Leighann Vivanco 9377110680;Una Randles 6106365199;Kaitlyn Sesco 3025912635;Ellan Dolin 2646078876;Alfonzo Luff 1303762828;Phillis Wernick 9003110134;Phillis Wernick 9338049111;Tonda Clem 2935054462;Sadye Brindley 9918775178;Christin Campos 2809054115;Aleisha Wing 4004534404;Meryl Maul 6859467081;Roselia Horstman 3179145807;Richie Rech 1087377713;Evon Eckman 8197144372;Roselia Horstman 7704844171;Lily Linquist 7366545555;Evon Eckman 1240560421;Elinore Echols 1041129232;Roselia Horstman 1176223044;Terrell Taub 3030983911;Maida Mohler 4190772334;Hong Heindel 4865779980;Kirk Koren 9356334215;Irena Imler 1146140236;Lawana Lemaster 6985561865;Sadye Brindley 4985293931;Jackeline Jolin 6013363403;Sadye Brindley 6453133104;Trista Twiss 4444846350;Alva Ankrom 6073684588;Nathalie Nuss 2128995368;Sadye Brindley 5475929290;Hai Harney 6006429204;Meryl Maul 4238692363;Else Esquivel 6365923944;Hong Heindel 6878255179;Olympia Ortego 4117259728;Beckie Brinkerhoff 4188632986;Jeannette Jantzen 5921203334;Leda Langone 8940597235;Meryl Maul 1301954781;Wilson Winter 7440881546;Jeannette Jantzen 3032857101;Meryl Maul 9285373798;Herminia Mcshane 4398275022;Artie Baucom 2390213786;Katrice Heitkamp 5011284575;Latonia Massi 9285273798;Sanjuanita Hemenway 4398275022;Brandee Lytch 2390213786;Amee Millikin 5011284575;Makeda Ballou 5360054175;Leighann Vivanco 9377110680;Una Randles 6106365199;Kaitlyn Sesco 3025912635;Ellan Dolin 2646078876;Alfonzo Luff 1303762828;Phillis Wernick 9003110134;Phillis Wernick 9338049111;Tonda Clem 2935054462;Sadye Brindley 9918775178;Christin Campos 2809054115;Aleisha Wing 4004534404;Meryl Maul 6859467081;Roselia Horstman 3179145807;Richie Rech 1087377713;Evon Eckman 8197144372;Roselia Horstman 7704844171;Lily Linquist 7366545555;Evon Eckman 1240560421;Elinore Echols 1041129232;Roselia Horstman 1176223044;Terrell Taub 3030983911;Maida Mohler 4190772334;Hong Heindel 4865779980;Kirk Koren 9356334215;Irena Imler 1146140236;Lawana Lemaster 6985561865;Sadye Brindley 4985293931;Jackeline Jolin 6013363403;Sadye Brindley 6453133104;Trista Twiss 4444846350;Alva Ankrom 6073684588;Nathalie Nuss 2128995368;Sadye Brindley 5475929290;Hai Harney 6006429204;Meryl Maul 4238692363;Else Esquivel 6365923944;Hong Heindel 6878255179;Olympia Ortego 4117259728;Beckie Brinkerhoff 4188632986;Jeannette Jantzen 5921203334;Leda Langone 8940597235;Meryl Maul 1301954781;Wilson Winter 7440881546;Jeannette Jantzen 3032857101;Meryl Maul 9285373798;Herminia Mcshane 4398275022;Artie Baucom 2390213786;Katrice Heitkamp 5011284575;Latonia Massi 9285273798;Sanjuanita Hemenway 4398275022;Brandee Lytch 2390213786;Amee Millikin 5011284575;Makeda Ballou 5360054175;Leighann Vivanco 9377110680;Una Randles 6106365199;Kaitlyn Sesco 3025912635;Ellan Dolin 2646078876;Alfonzo Luff 1303762828;Phillis Wernick 9003110134;Phillis Wernick 9338049111;Tonda Clem 2935054462;Sadye Brindley 9918775178;Christin Campos 2809054115;Aleisha Wing 4004534404;Meryl Maul 6859467081;Roselia Horstman 3179145807;Richie Rech 1087377713;Evon Eckman 8197144372;Roselia Horstman 7704844171;Lily Linquist 7366545555;Evon Eckman 1240560421;Elinore Echols 1041129232;Roselia Horstman 1176223044;Terrell Taub 3030983911;Maida Mohler 4190772334;Hong Heindel 4865779980;Kirk Koren 9356334215;Irena Imler 1146140236;Lawana Lemaster 6985561865;Sadye Brindley 4985293931;Jackeline Jolin 6013363403;Sadye Brindley 6453133104;Trista Twiss 4444846350;Alva Ankrom 6073684588;Nathalie Nuss 2128995368;Sadye Brindley 5475929290;Hai Harney 6006429204;Meryl Maul 4238692363;Else Esquivel 6365923944;Hong Heindel 6878255179;Olympia Ortego 4117259728;Beckie Brinkerhoff 4188632986;Jeannette Jantzen 5921203334;Leda Langone 8940597235;Meryl Maul 1301954781;Wilson Winter 7440881546;Jeannette Jantzen 3032857101;Meryl Maul 9285373798;Herminia Mcshane 4398275022;Artie Baucom 2390213786;Katrice Heitkamp 5011284575;Latonia Massi 9285273798;Sanjuanita Hemenway 4398275022;Brandee Lytch 2390213786;Amee Millikin 5011284575;Makeda Ballou 5360054175;Leighann Vivanco 9377110680;Una Randles 6106365199;Kaitlyn Sesco 3025912635;Ellan Dolin 2646078876;Alfonzo Luff 1303762828;Phillis Wernick 9003110134;Phillis Wernick 9338049111;Tonda Clem 2935054462;Sadye Brindley 9918775178;Christin Campos 2809054115;Aleisha Wing 4004534404;Meryl Maul 6859467081;Roselia Horstman 3179145807;Richie Rech 1087377713;Evon Eckman 8197144372;Roselia Horstman 7704844171;Lily Linquist 7366545555;Evon Eckman 1240560421;Elinore Echols 1041129232;Roselia Horstman 1176223044;Terrell Taub 3030983911;Maida Mohler 4190772334;Hong Heindel 4865779980;Kirk Koren 9356334215;Irena Imler 1146140236;Lawana Lemaster 6985561865;Sadye Brindley 4985293931;Jackeline Jolin 6013363403;Sadye Brindley 6453133104;Trista Twiss 4444846350;Alva Ankrom 6073684588;Nathalie Nuss 2128995368;Sadye Brindley 5475929290;Hai Harney 6006429204;Meryl Maul 4238692363;Else Esquivel 6365923944;Hong Heindel

End accountsFile.txt

7536765490;Tatiana Harrison 984733122a:Jim Schwing Figure 1: Sample format of the file that needs to be parsed. "Errors" are shown in grey

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions