Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-17-2008, 03:20 AM
Member
 
Join Date: Jun 2008
Posts: 2
bluegti02 is on a distinguished road
Credit Card Validator
ok well i have to write a credit card validator

Code:
import java.util.*; // for the Scanner class public class CCValidator { public static void main (String [] args) { Scanner sc = new Scanner(System.in); System.out.print("Please enter a number to validate: "); long input = sc.nextLong(); boolean isValid = numberIsValid(input); System.out.print("This credit card number "); if (isValid) { System.out.print("is "); } else { System.out.print("is NOT "); } System.out.println("valid.\n"); } public static boolean numberIsValid (long num) { int checksum = 0; for ( int place = 0; place < 16; place++ ) { int digit = (int) ( num % 10 ); num /= 10; if ( ( place & 1 ) == 0 ) { checksum += digit; } else { checksum += ( digit ); } if ( num == 0 ) { break; } } return ( checksum % 10 ) == 0; } }



these are the instructions given to us

Quote:
One validation algorithm is the LUHN formula. This formula works as follows:

1. Set the sum to 0
2. Add up the digits in the credit card number, working from right to left:
* If the digit has an odd position, counting from the right, add it to the sum as-is. Thus, the first, third, etc. digits (counting from the right) are all added directly to the sum.
* Otherwise, double the value of the current digit. If it is over 10, add the digits to get a number less than 10. Then add the result to the sum.
3. If the sum divides evenly by 10 (i.e., with a remainder of 0), then the credit card number is valid. Otherwise, the card number is invalid.

For example, consider the (abbreviated and fictional) card number 499673. Doubling alternate digits (4, 9, 7), we get: (4 * 2) + 9 + (9 * 2) + 6 + (7 * 2) + 3

(9 * 2) and (7 * 2) are greater than 10, so we add the digits: (9 * 2) = 18 = (1 + 8) = 9. Doing the same for 7, we get 5. HINT: you can also just subtract 9 from the doubled digit.

The sum of these digits is 40, which divides evenly by 10, so this number is valid.
and well im terribly stuck its my 2nd maybe 3rd week of classes and afraid of falling behind if any1 can offer help or a place to look for some advice that would be wonderful
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-17-2008, 05:31 AM
Member
 
Join Date: Jun 2008
Posts: 2
bluegti02 is on a distinguished road
close this thread please
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-17-2008, 07:09 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,574
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
What's the reason to close this.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] File I/O Extra Credit Assignment FTW! Bascotie New To Java 9 06-10-2008 09:20 AM
Getting network card address in Java 6 Java Tip Java Tips 0 03-02-2008 08:10 PM
a little help needed for card drawing carlos123 New To Java 3 01-09-2008 04:40 AM
Card program , need help thanks. carlos123 New To Java 2 12-31-2007 08:23 AM
Struts Validator - JScript version of Validator ´validwhen´ Felissa Web Frameworks 1 07-06-2007 05:39 PM


All times are GMT +3. The time now is 08:24 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org