From 9efb4636e87a77b5b698fad21b2611f3868b573b Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Fri, 11 Nov 2022 13:01:30 -0600 Subject: [PATCH] Work on MP4 --- .gitignore | 2 + .../mp4_calebfontenot/MP4_CalebFontenot.java | 74 ++++++++++--------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 8bd1954..7e3f03e 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ /Assignments/MP4_CalebFontenot/nbproject/private/ /Assignments/lab14_CalebFontenot/nbproject/private/ /Assignments/lab14_CalebFontenot/build/ +/Assignments/MP4_CalebFontenot/build/ +/Assignments/MP4_CalebFontenot/dist/ diff --git a/Assignments/MP4_CalebFontenot/src/mp4_calebfontenot/MP4_CalebFontenot.java b/Assignments/MP4_CalebFontenot/src/mp4_calebfontenot/MP4_CalebFontenot.java index 4665334..965406a 100644 --- a/Assignments/MP4_CalebFontenot/src/mp4_calebfontenot/MP4_CalebFontenot.java +++ b/Assignments/MP4_CalebFontenot/src/mp4_calebfontenot/MP4_CalebFontenot.java @@ -9,19 +9,16 @@ package mp4_calebfontenot; * * @author caleb */ -public class MP4_CalebFontenot -{ +public class MP4_CalebFontenot { /** - * If the result from Step 4 is divisible by 10, the card number is valid; - * otherwise, it is invalid. For example, the number 4388576018402626 is - * invalid, but the number 4388576018410707 is valid + * If the result from Step 4 is divisible by 10, the card number is valid; otherwise, it is invalid. For example, the number 4388576018402626 is invalid, but the number 4388576018410707 is valid * * @param CreditCard * @return */ - public static boolean isValid(String CreditCard) - { + public static boolean isValid(String CreditCard) { + return true; } @@ -32,64 +29,75 @@ public class MP4_CalebFontenot * @param step3 result form step 3 * @return */ - public static int sum(int step1andSep2, int step3) - { + public static int sum(int step1andSep2, int step3) { return step1andSep2 + step3; } /** - * Add all digits in the odd places from right to left in the card number. 6 - * + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38 + * Add all digits in the odd places from right to left in the card number. 6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38 * * @param -creditCard the credit card number to be processed. * @return the sum of digits at odd position from right to left. */ - public static int addOddNumbersFromRightToLeft(String creditCard) - { + public static int addOddNumbersFromRightToLeft(String creditCard) { return -1; } /** - * Double every second digit from right to left. If doubling of a digit - * results in a two-digit number, add up the two digits to get a - * single-digit number. 2 * 2 = 4 2 * 2 = 4 4 * 2 = 8 1 * 2 = 2 6 * 2 = 12 - * (1 + 2 = 3) 5 * 2 = 10 (1 + 0 = 1) 8 * 2 = 16 (1 + 6 = 7) 4 * 2 = 8 Step - * 2 Now add all single-digit numbers from Step 1. 4 + 4 + 8 + 2 + 3 + 1 + 7 - * + 8 = 37 + * Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number. 2 * 2 = 4 2 * 2 = 4 4 * 2 = 8 1 * 2 = 2 6 * 2 = 12 (1 + 2 = 3) 5 * 2 = 10 (1 + 0 = 1) 8 * 2 = 16 (1 + 6 = 7) 4 * 2 = 8 Step 2 Now add all single-digit numbers from Step 1. 4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37 * * @param -creditCard the credit card number to be processed. * @return */ - public static int doubleDigitsAndSumSingleDigits(String creditCard) - { + public static int doubleDigitsAndSumSingleDigits(String creditCard) { + // Iterate through string + int creditCardLength = creditCard.length(); + int currentDigit, digitProduct, tensDigit, onesDigit; + //System.out.println(creditCard.length()); + + for (int i = 15; i >= 0; i = i - 2) { + currentDigit = Character.getNumericValue(creditCard.charAt(i)); // Parses current digit as an integer so we can do math on it + digitProduct = currentDigit * 2; + System.out.println(digitProduct); + if (digitProduct > 9) { // Product is larger than 9 + tensDigit = currentDigit / 10 % 10; + onesDigit = currentDigit / 1 % 10; + System.out.println("tensDigit is " + tensDigit); + System.out.println("onesDigit is " + onesDigit); + } + + } return -1; } /** - * Displays Q/q or C/c. If the user enters C, it read the credit number and - * returns it as String. If the user types Q/q returns 0 + * Displays Q/q or C/c. If the user enters C, it read the credit number and returns it as String. If the user types Q/q returns 0 * * @return a string with credit card number or 0. */ - public static String menu() - { + public static String menu() { return "creditcard number or 0"; } -/** - * - * @param args - */ - public static void main(String[] args) - { + + /** + * + * @param args + */ + public static void main(String[] args) { + // DEBUG + //System.out.println(isValid("4388576018402626")); + MP4_CalebFontenot.doubleDigitsAndSumSingleDigits("4388576018402626"); + /* String userInput = menu(); + while (!userInput.equals("0") )//user has not entered Q/q { - MP4.doubleDigitsAndSumSingleDigits(userInput); + MP4_CalebFontenot.doubleDigitsAndSumSingleDigits(userInput); //complete the code userInput = menu(); } + */ } } -