Skip to content

Commit

Permalink
Update CheckDigit.java
Browse files Browse the repository at this point in the history
  • Loading branch information
breadsticker1 authored Apr 30, 2024
1 parent 89d5f76 commit 5302281
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/CheckDigit.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public class CheckDigit
public static int getCheck(int num)
{
/* to be implemented in part (a) */
int sum = 0;
for(int i = 1; i < getNumberOfDigits(num); i++)
sum += (8-i)*getDigit(num,1);
return sum%10;
}

/** Returns true if numWithCheckDigit is valid, or false
Expand All @@ -18,7 +22,13 @@ public static int getCheck(int num)
*/
public static boolean isValid(int numWithCheckDigit)
{
/* to be implemented in part (b) */
/* to be implemented in part (b) */
int check = numWithCheckDigit%10;
int dog = numWithCheckDigit/10;
int newCheck = getCheck(dog);
if(check == newCheck)
return true;
return false;
}

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

0 comments on commit 5302281

Please sign in to comment.