I have a BYOL (Build your own Lab) for my Computer Science class. This lab is due in 3 days, and I need a bit of help on one of the parts. I would like to know how to determine if the user has input a special character (@, #, !, *, $, c, %, etc) and I want to know how to close the string if that character is not included in the string. I am using an if...then loop to close strings when the user's input is not in the correct format. (Ex: I asked them to input their SSN, so it must be in the format XXX-XX-XXXX, otherwise it will close the string.) I need to ask them for their E-Mail address and want the answer to include "@". All help is appreciated.
Here is my code, because I do not know how to post it separately.
public static void main (String[]args)
{
String answer;
do {
Scanner word=new Scanner(System.in);
Scanner input=new Scanner(System.in);
System.out.print("Oh No! It appears that Dwayne \"The Rock\" Johnson has stolen your Credit Card and SSN Info!");
System.out.print("\nPlease input some information for us to secure your personal Info.");
System.out.print("\n\nPlease enter your Social Security Number: (XXX-XX-XXXX) ");
System.out.print("\nPlease be aware that you must input the information in the correct format (Without the parentheses at the begining and end) ");
String ssn=input.nextLine();
if (ssn.length()!=11)
System.out.println("\nYou have entered the incorrect format! (XXX-XX-XXXX)" );
if (ssn.length()!=11)
System.exit(0);
System.out.print("\nPlease enter your Credit Card Number:(XXXX-XXXX-XXXX-XXXX) ");
String ccn=input.nextLine();
if (ccn.length()!=19)
System.out.println("\nYou have entered the incorrect format! (XXXX-XXXX-XXXX-XXXX)");
if (ccn.length()!=19)
System.exit(0);
System.out.print("\nPlease enter your Credit Card Expiration Date: (MM/YY) ");
String exp=word.nextLine();
System.out.print("\nPlease enter your CVV (Card Verification Value): (XXX) ");
String back=word.nextLine();
if (back.length()!=3)
System.out.println("\nYou have entered the incorrect format! (XXX)");
if (back.length()!=3)
System.exit(0);
System.out.print("\nPlease enter your E-Mail Address: ");
String mail=word.nextLine();
System.out.print("\nPlease enter your American Phone Number: (+1(XXX) XXX-XXXX) ");
String phone=word.nextLine();
if (phone.length()!=16)
System.out.println("\nYou have entered the incorrect format! (+1(XXX) XXX-XXXX)");
if (phone.length()!=16)
System.exit(0);
System.out.print("\nPlease enter your home address: ");
String home=word.nextLine();
System.out.print("\nPlease enter your First Name: ");
String name=word.nextLine();
System.out.print("\nPlease enter your Middle Initial (X): ");
String mid=word.nextLine();
if (mid.length()!=1)
System.out.println("\nYou have entered the incorrect format! (X)");
if (mid.length()!=1)
System.exit(0);
System.out.print("\nPlease enter your Last Name: ");
String last=word.nextLine();
System.out.print("\nPlease enter your Date of Birth: (MM/DD/YYYY) ");
String dob=word.nextLine();
if (dob.length()!=10)
System.out.println("\nYou have entered the incorrect format! (MM/DD/YYYY)");
if (dob.length()!=10)
System.exit(0);
System.out.println("\n\n\t\t\t\tThank you, you have secured your information");
System.out.println("\nIf you have any comments or concerns, please contact us at these locations:");
System.out.println("\n\n\t+1(555) 555-5555");
System.out.println("\n\tgoogleuser@gmail.com");
System.out.println("\n\n\t\t\t\t\t\tThank you, and have a wonderful day!");
System.out.println("\n\t\t\t\t\t\t\tThe Scammer Preventer™ Team");
System.out.println("\n\n\n\t\t\t\t\tDo you have more information to input? Yes or No: ");
answer=input.next();
}
while (answer.equalsIgnoreCase("\n\nYes"));
}
}