Skip to content

Commit

Permalink
Update CheckDigit.java
Browse files Browse the repository at this point in the history
  • Loading branch information
5ammich authored Apr 30, 2024
1 parent 70cb2b2 commit 98adfb1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/CheckDigit.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ public class CheckDigit
public static int getCheck(int num)
{
/* to be implemented in part (a) */

int adder = 0;
int multiplier = 7;
for (int i = 1; i <= getNumberOfDigits(num); i++){
adder = adder + (getDigit(num,i) * multiplier);
multiplier--;
}
return (getDigit(adder, getNumberOfDigits(adder)));
}

/** Returns true if numWithCheckDigit is valid, or false
Expand All @@ -19,6 +27,12 @@ public static int getCheck(int num)
public static boolean isValid(int numWithCheckDigit)
{
/* to be implemented in part (b) */

int storer = getCheck(numWithCheckDigit/10);
if (storer == (numWigthCheckDigit % 10){
return true;
}
return false;
}

/** Returns the number of digits in num. */
Expand Down

0 comments on commit 98adfb1

Please sign in to comment.