Coding java program to calculate check digit numbers

7.7k views Asked by At

I have this java project(using eclipse) that calculates check digit numbers. I'm stuck on how to code this one.

The check has a check digit so that it makes the sum of the sights including the check digit divisible by 7. Assume there are always 4 digits plus the check digit. The sample is 3875 with the number being 5 Second trial problem is 5862 and check number needs to be found. How do I go about doing this? I got to entering each digit and adding them but how can i do the rest?

This is for an into to computer science class so please no super complex stuff as if we didn't learn it I cant use it.

My teacher sucks by the way we learn none of this. I already did part a I need part b. Thanks. Here's an image to hell clarify.

Question

1

There are 1 answers

3
Frakcool On BEST ANSWER

First of all, you need to develop some "programmer logic", these problems help to develop it.

Airline tickets divide the actual identification number by 7 and assign the remainder to the check digit. Number can be of any length

Example:

12358 #3

Let's break this example:

12358 / 7 = 1765

and the reminder is 3

Let's do the same with the 2nd number on the example:

45349 / 7 = 45346

and the reminder is 3

So, your logic is correct.

An American Express traveler's check has a digit so that it maskes the sum of the digits, including the check digit, evenly divisible by 7.

Example:

3875 #5

In this problem the thing is a little different, you need to sum the digits:

3875 -> 3 + 8 + 7 + 5 = 23

Now you need to get the reminder of 23 / 7

23 / 7 = 3

And a reminder of 2

7 - 2 = 5

That's your checkDigit

5862

5862 -> 5 + 8 + 6 + 2 = 21

21 / 7 = 3

Reminder = 0

checkDigit = 7 - 0 = 7

So the formula is:

  1. Split the number into digits
  2. Sum the digits
  3. Get the mod 7 of the sum
  4. Make a rest of 7 - reminder