Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// TODO #3: Write the code here to test for the input name error condition : //String must contain only alphabetic characters, lower/upper case //plus

// TODO #3: Write the code here to test for the input name error condition :

//String must contain only alphabetic characters, lower/upper case

//plus optionally 1 character from this set: (space, quote (') , dash(-), dot(.) )

// The optional characters, if present, cannot be at the end of the string or at the beginning

// For example, you might have :

// O'Connor, St. James, St-Armand

// But not:

// Jeremy' , -John, John.

// and throw a new BadAccountInputException with the message 'Bad Name Format'

// This exception will be caught in the calling method in AccountFileSaver class.

// Note that this test is used in checking the setters for both the first

// and last names, below.

// Return true only if no error occurs at all in the method

if(!name.contains("'")||!name.contains(".")||!name.contains("-")) {

if(!name.matches("^[a-z]*")||!name.matches("^[A-Z]*"))

throw new BadAccountInputException("must contain only alphabetic characters, lower/upper case");

}else {

String[] tmp=new String[5];

if(name.contains("'")) {

tmp=name.trim().split("'");

}else if(name.contains(".")) {

tmp=name.trim().split(".");

}else if(name.contains("-")) {

tmp=name.trim().split("-");

}

String firstName=tmp[0];

String lastName=tmp[1];

if(!firstName.matches("^[a-z]*")||!firstName.matches("^[A-Z]*"))

throw new BadAccountInputException("must contain only alphabetic characters, lower/upper case");

if(!lastName.matches("^[a-z]*")||!lastName.matches("^[A-Z]*"))

throw new BadAccountInputException("must contain only alphabetic characters, lower/upper case");

if(firstName==null||lastName==null)

throw new BadAccountInputException("Bad Name Format");

}

return true;

i wanna know how to solve this in other way

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

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions