GIVENS: (none) /* the main method calls the other methods in order to solve RESULT: (none) particular */ INTERMEDIATE: digits (reference to an integer array of digits) public static void main (String [ ] args) { n (number of elements in the array) int [ ] digits; // reference variable to array of digits testValid (Indicated if card is valid) boolean testValid; // indicates if card is valid HEADER: main // body BODY: digits = DigitsLib.readDigits( ); // call to read the data while ((digits.length == 4) && (!DigitsLib.isZero(digits))) { // sends the number to the valid() method testValid = valid(digits); // print the result if (testValid) { System.out.println("This number is valid."); } else { System.out.println("This number is invalid."); } } } GIVENS: digits (reference to array of digits) /* This method validates the credit card number */ n (number of elements in the array) private static boolean [ ] digits) { RESULT: isValid (TRUE if card number is FALSE otherwise) ITERMEDIATE: int firstThree; // first three digits of last group int lastDigit; // last digit of credit card number firstThree (first three digits of last group) int sum; // sum of first 15 digits lastDigit (last of credit card number) boolean isValid; // result: true if number is valid sum (sum of 15 digits) // find the first 3 digits pf the last group HEADER: isValid valid(digits, n) firstThree = BODY: // find the last digit of the number lastDigit = // find the sum of the first 15 digits sum = // determines the validity = isValid return isValid; } DigitsLib Class (DigitsLib.java)
GIVENS: (none) RESULT: (none) INTERMEDIATE: digits (reference to an integer array of digits) n (number of elements in the array) testValid (Indicated if card is valid) HEADER: main BODY: /* the main method calls the other methods in order to solve particular */ public static void main (String [ ] args) { int [ ] digits; // reference variable to array of digits boolean testValid; // indicates if card is valid // body digits = DigitsLib.readDigits( ); // call to read the data while ((digits.length == 4) && (!DigitsLib.isZero(digits))) { // sends the number to the valid() method testValid = valid(digits); // print the result if (testValid) { System.out.println("This number is valid."); } else { System.out.println("This number is invalid."); } } } GIVENS: digits (reference to array of digits) n (number of elements in the array) RESULT: isValid (TRUE if card number is FALSE otherwise) ITERMEDIATE: firstThree (first three digits of last group) lastDigit (last of credit card number) sum (sum of 15 digits) HEADER: isValid valid(digits, n) BODY: /* This method validates the credit card number */ private static boolean [ ] digits) { int firstThree; // first three digits of last group int lastDigit; // last digit of credit card number int sum; // sum of first 15 digits boolean isValid; // result: true if number is valid // find the first 3 digits pf the last group firstThree = // find the last digit of the number lastDigit = // find the sum of the first 15 digits sum = // determines the validity isValid = return isValid; } DigitsLib Class (DigitsLib.java)
ITI1120WorkBook.docx