Work on MP4
This commit is contained in:
parent
3476dd253a
commit
9efb4636e8
2
.gitignore
vendored
2
.gitignore
vendored
@ -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/
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user