Code: package chapter.pkg6.part.pkg2.assignment; import java.util.Scanner; /** * * @author matty */ public class Chapter6Part2Assignment { /** * @param args the command line arguments */ static long cardnumber= 4440967484181607L; public static void main(String[] args) { // asking for card number System.out.println("please enter the card number:/n"); System.out.println(cardnumber + "is"+ (validitychk(cardnumber)?"valid":"invlaid")); System.out.println(); } public static boolean validitychk(long cnumber) { //return statemnt return (thesize(cardnumber) >= 13 && thesize(cnumber) <= 16) && (prefixmatch(cardnumber, 4) || prefixmatch(cardnumber, 5) || prefixmatch(cnumber, 37) || prefixmatch(cardnumber, 6)) && ((sumdoubleeven(cnumber) + sumodd(cnumber)) % 10 == 0); } public static int thesize(long cardnumber){ String cardnumberString= cardnumber +""; return cardnumberString.length(); } public static boolean prefixmatch(longcardnumber, int num) { return true; } public static int sumdoubleeven(long cardnumber){ int sum = 0; String num = cardnumber + ""; for (int i = thesize(cardnumber) - 2; i >= 0; i -= 2) sum += getDigit(Integer.parseInt(num.charAt(i) + "") * 2); return sum; } public static int getDigit(int carnumber) { if (carnumber<9) return cardnumber; return cardnumber / 10 + cardnumber % 10; } public static int sumodd(long cardnumner){ int sum=0; String num=cardnumber+""; for(int i=thesize(cardnumber)-1;i>=0;i-=2) sum += Integer.parseInt(num.charAt(i)+""); return sum; } } I also attached an image where the issue was thanks!
Im having error issues with some code I wiritten was looking for help.
Code:
package chapter.pkg6.part.pkg2.assignment;
import java.util.Scanner;
/**
*
* @author matty
*/
public class Chapter6Part2Assignment {
/**
* @param args the command line arguments
*/
static long cardnumber= 4440967484181607L;
public static void main(String[] args) {
// asking for card number
System.out.println("please enter the card number:/n");
System.out.println(cardnumber + "is"+ (validitychk(cardnumber)?"valid":"invlaid"));
System.out.println(); }
public static boolean validitychk(long cnumber) {
//return statemnt
return (thesize(cardnumber) >= 13 && thesize(cnumber) <= 16) && (prefixmatch(cardnumber, 4)
|| prefixmatch(cardnumber, 5) || prefixmatch(cnumber, 37) || prefixmatch(cardnumber, 6))
&& ((sumdoubleeven(cnumber) + sumodd(cnumber)) % 10 == 0);
}
public static int thesize(long cardnumber){
String cardnumberString= cardnumber +"";
return cardnumberString.length();
}
public static boolean prefixmatch(longcardnumber, int num) {
return true;
}
public static int sumdoubleeven(long cardnumber){
int sum = 0;
String num = cardnumber + "";
for (int i = thesize(cardnumber) - 2; i >= 0; i -= 2)
sum += getDigit(Integer.parseInt(num.charAt(i) + "") * 2);
return sum;
}
public static int getDigit(int carnumber) {
if (carnumber<9)
return cardnumber;
return cardnumber / 10 + cardnumber % 10;
}
public static int sumodd(long cardnumner){
int sum=0;
String num=cardnumber+"";
for(int i=thesize(cardnumber)-1;i>=0;i-=2)
sum += Integer.parseInt(num.charAt(i)+"");
return sum;
}
}
I also attached an image where the issue was thanks!


Step by step
Solved in 2 steps









