File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff 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. */
You can’t perform that action at this time.
0 commit comments