Results 1 to 3 of 3

Thread: Any free JAVA coding?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    Penang, Malaysia
    Posts
    51
    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?

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    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
    Mark
    -------------------

  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    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");
    	}
    	
    	
    	}
    	}
    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width