Author | Message |
---|---|
jgarc659
Posts: 27
|
Posted 03:27 Apr 16, 2017 |
Hey everyone. I've been working on this one for a while and finally got it to function as intended just right now. I'm still concerned about one small aspect of its accuracy, though. The thing is, when I compare the results in my output file to the sample one posted online, I keep find one single discrepancy: The card number 422222222222 is marked "Valid" in my program but "Invalid" on the sample. I worked out the solution on paper using the given algorithm, and found it to be valid myself, meaning my program should be accurate. Does this mean there's something off about the sample? |
jzunig20
Posts: 38
|
Posted 03:31 Apr 16, 2017 |
your program might have a logic error somewhere, i just ran it on my program and i got invalid |
jgarc659
Posts: 27
|
Posted 03:38 Apr 16, 2017 |
You're right, I'm pretty sure I just caught on to the issue. |
jzunig20
Posts: 38
|
Posted 03:46 Apr 16, 2017 |
you might want to check your program if the card number starts with 4, then its a visa if its a visa, then it must have x amount of digits in it. the final number from the algorithm is divisible by 10, but thats not the only requirement a card number has to meet in order to be valid |
KA1997
Posts: 31
|
Posted 16:41 Apr 18, 2017 |
How do you check a certain digit in a number? Thats confusing because you can't charAt() a number like you could in a String. |
sdo8
Posts: 54
|
Posted 18:44 Apr 18, 2017 |
you can convert numbers to strings |
jzunig20
Posts: 38
|
Posted 18:55 Apr 18, 2017 |
Keenan taught us how to extract numbers its on one of the slides look into the mod operator that would help you with what you're looking for
also you would be able to process the number as a string you're just gonna have to review what string methods in the string class would be helpful (all in ch 4) |
sdo8
Posts: 54
|
Posted 20:28 Apr 18, 2017 |
convert the number to a string, then convert each character to an integer using a loop. You can decide what to do with the result |
KA1997
Posts: 31
|
Posted 20:49 Apr 18, 2017 |
I tried to and it said I can't cast from int to string |
bliu14
Posts: 10
|
Posted 21:53 Apr 18, 2017 |
To convert an int to a string: Adding the empty string converts the int to a string. Hope it helps! |
jgarc629
Posts: 76
|
Posted 18:09 Apr 19, 2017 |
For the algorithm, I'm trying to separate the digits from 5535085286738004. I classified it as a long, would casting it as an int be a problem? |
sdo8
Posts: 54
|
Posted 11:16 Apr 20, 2017 |
Yes. If the number is bigger than 2,147,483,647 or less than -2,147,483,648 (which is the range of an integer), you will have errors. |