Credit card companies use built-in "checksums" as added security measures when creating the account numbers on credit cards. This means that there are only certain valid credit card numbers, and validity can instantly be detected by using an algorithm that may involve adding up parts of the numbers or performing other checks. In this problem, you will implement a security algorithm on a credit card number, and your program will indicate whether or not the card number is valid, according to the security check. Note that this algorithm is purely made-up; don't try to use it to detect fake credit card numbers!
To check that the credit card number is valid, verify that it conforms to the following rules:
Hint: valid card numbers according to this set of rules include 480760521766 and 409434602754. You should use these for testing out your program.
Your job is to create a CreditCard class that represents a card number as a String. Hence you will have an instance variable of type String to store this. In addition the CreditCard class must have a mutator method called check( ) that determines if the credit card is valid or not. This information (whether the card is valid or not) should be stored in an instance variable of type boolean. Your class should also have an accessor method called isValid( ) that returns the value of this boolean. Your class CreditCard should also have an instance variable of type int called errorCode. This variable should be initialized to 0 and changed to an integer between 1 and 6 if the CreditCard object fails one of the tests above. That is, the check( ) method should change errorCode to the number corresponding to the first test the number failed. If the number does not fail any tests then you can leave the errorCode variable at 0. Finally, you should have an accessor method called getErrorCode( ) that returns the value of the variable errorCode. You might find this method useful when you are verifying that your check( ) method works correctly.
Attached you will find a test class called CreditCardTester. Your CreditCard class must work with the test class provided without modification. You must NOT alter the test class.
To complete this problem, you will need to use various methods of the String class, described in Horstmann and in the Java online documentation for String. In particular, you should use methods for getting the character at a certain index and for converting characters to Strings. You will also need to use the Integer.parseInt method to convert a String to an int.