Skip to content

Commit 433457f

Browse files
author
AlaBuck
authored
Update CheckDigit.java
1 parent 2ec33dd commit 433457f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main/java/CheckDigit.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public class CheckDigit
88
public static int getCheck(int num)
99
{
1010
/* to be implemented in part (a) */
11+
int premoddeddigit = 0;
12+
for(int i=0; i<=getNumberOfDigits(num); i++){
13+
premoddeddigit+=(8-i)*getDigit(num, i);
14+
}
15+
return premoddeddigit%10
1116
}
1217

1318
/** Returns true if numWithCheckDigit is valid, or false
@@ -18,7 +23,14 @@ public static int getCheck(int num)
1823
*/
1924
public static boolean isValid(int numWithCheckDigit)
2025
{
21-
/* to be implemented in part (b) */
26+
int check = numWithCheckDigit % 10;
27+
int num = numWithCheckDigit / 10;
28+
int newCheck = getCheck(num);
29+
if(check == newCheck) {
30+
return true;
31+
} else {
32+
return false;
33+
}
2234
}
2335

2436
/** Returns the number of digits in num. */

0 commit comments

Comments
 (0)