reset password
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 |
jzunig20 wrote:

your program might have a logic error somewhere, i just ran it on my program and i got invalid 

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 |
sdo8 wrote:

you can convert numbers to strings

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:

String s = (int) + "";

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 |
jgarc629 wrote:

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?

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.
With a number as large as 5,535,085,286,738,004, which is between −9,223,372,036,854,775,808 and 9,223,372,036,854,775,807 (the range of a long), using an integer to store this kind of value would not work. If your program is finding the individual digits, you would be able to cast the ending result into a integer (assuming that the value will be one number, which would be in the range of an integer). However, I wouldn't even try using an integer to store 5535085286738004.