Question
// 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
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