Click to See Complete Forum and Search --> : Any free JAVA coding?
leeckeat
Nov 16th, 2000, 10:28 AM
Hi,
Where i can download some free JAVA code/application?
i need to find some credit card validation machanism written in JAVA ..can anyone help me?
Mark Sreeves
Nov 21st, 2000, 08:35 AM
I'm working on it! :)
this is want you want in VB
(thanks to Aaron Young)
see thread: http://forums.vb-world.net/showthread.php?threadid=3034
I'm trying to convert it to java for you but I'm having trouble getting my head around the if iif()then line
Option Explicit
Private Function CheckCreditCard(ByVal sNumber As String) As Boolean
Dim iCount As Integer
Dim iDigit As Integer
Dim iTotal As Integer
For iCount = 1 To Len(sNumber)
iDigit = Val(Mid$(sNumber, iCount, 1))
If IIf(Len(sNumber) Mod 2, iCount Mod 2 = 0, iCount Mod 2) Then
iDigit = iDigit * 2
If iDigit > 9 Then iDigit = iDigit - 9
End If
iTotal = iTotal + iDigit
Next
If iTotal Mod 10 = 0 And Len(sNumber) > 0 Then CheckCreditCard = True
End Function
Private Sub Command1_Click()
If CheckCreditCard(Text1) Then
MsgBox "Credit Card Verified"
Else
MsgBox "Credit Card Invalid"
End If
End Sub
Mark Sreeves
Nov 22nd, 2000, 02:59 AM
Got it!
(NOTE: this is for use on the command line rather than an applet)
For some unknown reason my compliler objected to my using Integer.parseInt to convert from a numerical char to an integer so I used a byte array instead.
import java.io.*;
public class cardchecker{
public static void main(String[] args) throws IOException {
byte[] sNumber = args[0].getBytes();
int iCount = 0;
int iDigit = 0;
int iTotal = 0;
for(iCount = 0; iCount < sNumber.length;iCount++)
{
iDigit = sNumber[iCount] - 48;
//System.out.println(iDigit);
boolean b = false;
if ((sNumber.length % 2 )== 1)
{
b =(((iCount+1) %2) == 0);//icount runs from 0 NOT 1
}else{
b = (((iCount+1) %2) == 1);
}
//System.out.println("b is : " + b );
if(b==true)
{
iDigit *= 2;
if(iDigit > 9)
{
iDigit -= 9;
}
}
iTotal += iDigit;
};
// System.out.println("iTotal: " + iTotal%10);
if((iTotal % 10 == 0) && (sNumber.length > 0))
{
System.out.println("Credit Card Verified");
}else{
System.out.println("Credit Card Invalid");
}
}
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.