Skip to content

Commit

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

/** Returns true if numWithCheckDigit is valid, or false
Expand All @@ -18,7 +25,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 check1 = getCheck(numWithCheckDigit / 10);
int check2 = check % 10;
if(check1 == check2){
return true;
}
return false;
}

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

0 comments on commit 0668ccb

Please sign in to comment.