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