我需要在java中做一些东西来生成随机卡号并检查它是否有效。这是我们在 main 中必须拥有的代码
public enum CardType { VISA, MASTER, AMERICAN_EXPRESS, DISCOVERY }
public static void main(String[] args) {
CardType type = CardType.VISA;
String cardNumber = generateCardNumber(type);
System.out.println("Generated " + type + " number " + cardNumber + " validity check: " + isValid(cardNumber));
type = CardType.MASTER;
cardNumber = generateCardNumber(type);
System.out.println("Generated " + type + " number " + cardNumber + " validity check: " + isValid(cardNumber));
}
现在我需要使用这个方法。但是我怎样才能使它(CardType type = CardType.VISA;)工作?我需要返回什么?一点帮助将挽救我的生命:)
public static String generateCardNumber(CardType cardType){
Random rnd = new Random();
int counter=0;
while(counter<=16){
int generate = rnd.nextInt(9);
counter++;
}
return ??;
}