I'm using java to write a program for class. I have the first portion of code written but I can't quite figure out what I'm doing wrong. When I run the program it lets me enter a card number but then it gives me an error. My professor said that it's because for this program the card number is too long to be stored as an int. I understand that, so it's being stored in a String. But I'm still getting an error. Help please.
package creditCard;
import java.util.Scanner;
public class Card {
public static void main(String[] args) {
//Set up a scanner
Scanner in = new Scanner(System.in);
//Set up a boolean named creditCard and set it to false
boolean validCreditCard = false;
//Loop while not a valid credit card
while (!validCreditCard) {
//Prompt the user for a potential credit card number
System.out.print("Please enter a card number: ");
//Get the credit card number as a String - store in potentialCCN
String potentialCCN = in.next();
//Use Luhn to validate a credit card
//Store the digit as an int for later use in lastDigit
int lastDigit = Integer.parseInt(potentialCCN);
//Test then comment out! -check the last digit
System.out.println(lastDigit+"Check the last digit");
//Remove the last digit from potentialCCN and store in potentialCCN using String's substring
potentialCCN = potentialCCN.substring(15);
//Test then comment out! - check potential credit card number
System.out.println(potentialCCN);
}
}
}