Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: HELP! Luhn Algorithm Credit Card Validation

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HELP! Luhn Algorithm Credit Card Validation

    Hi Every One
    Hope you're doing well !

    any how

    i'm really desperate i need a java program
    the promotes the user to enter a Credit Card as a long number
    then check for validation using Luhn Algorithm which i need to use methods for luhn rules .
    I also have to take the long number of the credit card and assign it into an array after i apply
    luhn rules in other methods .

    hope you understand
    and hope you heeeeeelp me pleeeeeeeeeeeeeeeeeas

    Thanxx .


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,349
    My Mood
    Mellow
    Thanks
    254
    Thanked 785 Times in 770 Posts

    Default Re: HELP! Luhn Algorithm Credit Card Validation

    We understand, but what have you tried?

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HELP! Luhn Algorithm Credit Card Validation

    i didn't know how to take the variable credit card number and assign it to an array after i'm finished ?


    this is my code i took the credit card number as an array from the begging
    and that's wrong .
    i'm stuck

    import java.util.Scanner ;
    public class creditValidation {

    public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    long[] cardNmbers = new long [16];

    do {
    System.out.print("Enter a card number with 16 digit : ");
    for (int i=0 ; i<cardNmbers.length ; i++ ){
    cardNmbers[i] = input.nextInt();
    multplyAndSum(cardNmbers[i]);
    addOdd(cardNmbers[i]);
    int summation = (int) (multplyAndSum(cardNmbers[i]) + addOdd(cardNmbers[i]));
    System.out.println(cardNmbers[i] + "\n" + isTrue(cardNmbers[i],cardNmbers[i]));

    }
    }
    while ((cardNmbers[0]!=4) ||(cardNmbers[0]!=5) || (cardNmbers[0]!=3 && cardNmbers[1]!=7) );
    }



    public static int multplyAndSum(long[] num1){
    long num = long[]num1 ;
    int sum = 0 , rem = 0 ;
    while (num>0)
    rem=rem%10;
    num = num/10;
    sum = sum * 10 + rem ;
    System.out.println(num*2);
    if (num>9){
    num= num % 10 + num / 10;
    }
    sum +=num ;
    return (int) sum ;
    }

    public static long addOdd (long [] oddNum){

    int sum = 0;
    int rem=0;
    int count = 0 ;

    while (oddNum>0){
    oddNum=oddNum/10;
    rem=rem%10;
    count++;
    if (count%2==1)
    sum+=oddNum;

    }
    return sum;

    }

    public static boolean isTrue(long odd , long even){
    multplyAndSum(even);
    addOdd(odd);
    int summation = (int) (multplyAndSum(even) + addOdd(odd));
    if (summation%10==0)
    return true ;
    else
    return false ;
    }

    }

    ^ it's all wrong :'(

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,349
    My Mood
    Mellow
    Thanks
    254
    Thanked 785 Times in 770 Posts

    Default Re: HELP! Luhn Algorithm Credit Card Validation

    Read this FAQ for instructions on how to post code correctly and other useful tips for newcomers. Also, tell us what you think is wrong or what you'd like help with. Post errors, sample runs, whatever it takes to explain what's wrong with your code or why you're stuck and ask specific questions about what you don't understand that will help you move forward.

    This sentence, "i didn't know how to take the variable credit card number and assign it to an array after i'm finished," doesn't make sense. You might look at the String API to get ideas on what can be done with String objects to accomplish what you're trying to do.

Similar Threads

  1. Luhn Algorithm(Mod10) Help (Beginner)
    By IBeeJava in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 1st, 2013, 10:12 AM
  2. Credit Card String Program
    By hotshotennis in forum What's Wrong With My Code?
    Replies: 13
    Last Post: December 6th, 2012, 04:17 PM
  3. Credit card help
    By kostas198 in forum Java Theory & Questions
    Replies: 1
    Last Post: November 6th, 2011, 10:50 PM
  4. Credit Card Problem (While and Switch will be used)
    By odun in forum Object Oriented Programming
    Replies: 3
    Last Post: March 29th, 2011, 01:54 AM
  5. Credit card validator
    By SOK in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 15th, 2010, 04:11 AM