Skip to content

Commit 970537a

Browse files
authored
Update CheckDigit.java
1 parent bc1cf2a commit 970537a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/main/java/CheckDigit.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ public class CheckDigit
55
* six, inclusive.
66
* num >= 0
77
*/
8-
public static int getCheck(int num)
9-
{
8+
public static int getCheck(int num){
109
/* to be implemented in part (a) */
1110
int sum = 0;
12-
for(int i = 1; i <= getNumberOfDigits; i++){
11+
for(int i = 1; i <= getNumberOfDigits(num); i++){
12+
sum += (8 - i) * getDigit(num, i);
1313
}
14+
return sum % 10;
1415
}
1516

1617
/** Returns true if numWithCheckDigit is valid, or false
@@ -21,11 +22,15 @@ public static int getCheck(int num)
2122
*/
2223
public static boolean isValid(int numWithCheckDigit){
2324
/* to be implemented in part (b) */
24-
int check = numWithCheck % 10;
25+
int check = numWithCheckDigit % 10;
26+
int num = numWithCheckDigit / 10;
27+
int newCheck = getCheck(num);
2528
if(check == newCheck){
2629
return true;
2730
}
28-
return false;
31+
else{
32+
return false;
33+
}
2934
}
3035

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

0 commit comments

Comments
 (0)