MP4/lab14
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mp4_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param CreditCard
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValid(String CreditCard)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sum the results from Steps 1, 2 and Step 3. 37 + 38 = 75
|
||||
*
|
||||
* @param step1andSep2 result form step 1 and step 2
|
||||
* @param step3 result form step 3
|
||||
* @return
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
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
|
||||
*
|
||||
* @param -creditCard the credit card number to be processed.
|
||||
* @return
|
||||
*/
|
||||
public static int doubleDigitsAndSumSingleDigits(String creditCard)
|
||||
{
|
||||
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
|
||||
*
|
||||
* @return a string with credit card number or 0.
|
||||
*/
|
||||
public static String menu()
|
||||
{
|
||||
return "creditcard number or 0";
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
String userInput = menu();
|
||||
while (!userInput.equals("0") )//user has not entered Q/q
|
||||
{
|
||||
MP4.doubleDigitsAndSumSingleDigits(userInput);
|
||||
//complete the code
|
||||
userInput = menu();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user