DevJourney · code I wrote while learning

README.md

2.3 KB

Invalid Credit Card Exception

Single File Programming Question

Problem Statement

Theo is trying to update his payment information on a subscription-based streaming service. To proceed, the system requires Theo to provide a valid credit card number consisting of 16 digits. However, Theo wants to make sure that the credit card number he enters meets the specified criteria with proper exception handling.

The credit card number must consist of exactly 16 digits. If the entered credit card number does not meet the specified criteria, the program should throw a custom exception, InvalidCreditCardException, and provide Theo with specific error messages: If the length of the credit card number is not 16 digits, the exception message should be: "Invalid credit card number length." If the credit card number contains non-numeric characters, the exception message should be: "Invalid credit card number format."

Implement a custom exception, InvalidCreditCardException, to fulfill Theo's requirements and keep his payment information secure.

Input:

format :

The input consists of a string value 's', consisting of the 16-digit credit card number.

Output:

format :

The output is displayed in the following format:

If the entered credit card number is valid, the program should output a success message:

"Payment information updated successfully!"

If the entered credit card has more than 16 digits or less than 16 digits it displays

"Error: Invalid credit card number length."

If the entered 16-digit credit card has non-integers it displays

"Error: Invalid credit card number format."

Refer to the sample output for formatting specifications.

Code constraints : In this scenario, the test cases fall under the following constraints:

The string s contains uppercase, lowercase, numerical values and special characters to at most 16 characters.

Sample test cases :

Input 1:

1234567890123456
Output 1 :
Payment information updated successfully!
Input 2 :
12345678901234
Output 2 :
Error: Invalid credit card number length.
Input 3 :
abcdefgh12345678
Output 3 :
Error: Invalid credit card number format.
Input 4 :
12345678901234567890
Output 4 :
Error: Invalid credit card number length.
Input 5 :
856975@5869525%2
Output 5 :
Error: Invalid credit card number format.