|
-
Nov 16th, 2000, 11:28 AM
#1
Thread Starter
Member
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?
-
Nov 21st, 2000, 09:35 AM
#2
Frenzied Member
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
Code:
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
-
Nov 22nd, 2000, 03:59 AM
#3
Frenzied Member
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.
Code:
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");
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|