Skip to content

Commit

Permalink
Update CheckDigit.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mykinglebron authored Apr 30, 2024
1 parent d82e159 commit e98267a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/java/CheckDigit.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ 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, i);
}
return sum%10;
}

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

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

0 comments on commit e98267a

Please sign in to comment.