// ---------- UTILITIES CLASS public class Utilities { public static String vali
ID: 3818513 • Letter: #
Question
// ---------- UTILITIES CLASS
public class Utilities {
public static String validateCreditCard(String credit_card) throws InvalidCreditCardException
// simply returns back credit card passed to it if found valid, otherwise, throws exception.
// valid if credit_card contains 16 characters, and each character is a digit.
public static String validateAcctNum(String acct_num) throws InvalidAcctNumException
// simply returns back acct num passed to it if found valid, otherwise, throws exception.
// valid if acct_num exists in the collection of accounts.
}
Explanation / Answer
public class Utilities
{
public static String validateCreditCard(String credit_card) throws InvalidCreditCardException
{
if (credit_card == null || (credit_card.length() != 16))
{
throw new InvalidCreditCardException();
}
for(int i = 0; i < credit_card.length(); i++)
{
if(!Character.isDigit(credit_card.charAt(i)))
{
throw new InvalidCreditCardException();
}
}
return credit_card;
}
// simply returns back credit card passed to it if found valid, otherwise, throws exception.
// valid if credit_card contains 16 characters, and each character is a digit.
public static String validateAcctNum(String acct_num) throws InvalidAcctNumException
{
if (acct_num == null || (acct_num.length() != 16))
{
throw new InvalidAcctNumException();
}
for(int i = 0; i < acct_num.length(); i++)
{
if(!Character.isDigit(acct_num.charAt(i)))
{
throw new InvalidAcctNumException();
}
}
return acct_num;
}
// simply returns back acct num passed to it if found valid, otherwise, throws exception.
// valid if acct_num exists in the collection of accounts.
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.