At this point I'm fairly certain the code will run properly once I clear up all syntax errors. However I'm not really sure how to do this as I am not entirely familiar with Java. Any help is appreciated.
Thanks for your help everyone I'm now using NetBeans. I'm seeing lots of errors but I'm not sure how to fix them. The most common is "class, interface, or enum expected" ?
import javax.swing.*;
public class Main {
public static void main(String[] args) {
String cCNum;
int count= 0;
do {
cCNum= JOptionPane.showInputDialog(null,"Please enter a 13 or 16 digit" +
" credit card number");
count++;
if ( cCNum.length() < 13 )
cCNum= JOptionPane.showMessageDialog(null, "The credit card number is" +
" too small please look at the number and re-enter it");
else if ( cCNum.length() >16 )
cCNum= JOptionPane.showMessageDialog(null, "The credit card number is" +
"too large please look at the number and re-enter it");
}
while ( (cCNum.length() < 13) || (cCNum.length() > 16) && (count < 3) && validInt (cCNum) ));
if (count > 3){
JOptionPane.showInputDialog(null,"The numbers you entered were not " +
"valid.\nGoodbye.");
System.exit(0);
}
else {
JOptionPane.showMessageDialog(null,"Your credit card number is:"+ cCNum);
JOptionPane.showMessageDialog(null,"Your card is a" + cCType (cCNum) );
JOptionPane.showMessageDialog(null,"Your card is" + isValid(long.parselong(cCNum)) );
}
public static String cCType (String cC){
if (cC.startsWith("4")){
return "Visa";
}
else if (cC.startsWith("5")){
return "MasterCard";
}
else if (cC.startsWith("6")){
return "Discover";
}
else if (cC.startsWith("37")){
return "American Express";
}
else
return "Unknown card type";
}
public static boolean validInt(String num ){
try {
long.parselong (num);
return num.length()== 13 || num.length()== 16;
}catch(NumberFormatException e){
//If it is not a valid number return false.
return false;
}
}
public static boolean isValid (long num){
boolean error = false;
if ((sumOfEvenPlaces(num)+ sumOfOddPlaces (num))% 10) == 0)
return true;
else
return error;
}
public static int sumOfEvenPlaces (long num) {
int total= 0;
int add= 0;
number = (num)/10;
while (num !=0){
add= getDigits((num %10))*2;
total+=add ;
number = (num)/100;
}
return total;
}
public static int getDigits(int num) {
if ( num >= 10 ) {
return (num % 10);
}
else
return num;
}
public static int sumOfOddPlace(long num) {
int total = 0;
while (num > 0) {
sum += ( number % 10 );
num = (num)/100;
}
return total;
}
}
}