I have a user enter their social security number (fake number) and I need it in the format of 111-11-1111 including the dashes. If the user enters the information without the dashes, or goes over 999-99-9999, the program prompts the user to enter the correct information. Here is my code, how do I fix this? Also, can I use a StringBuilder
for any part of this?
import java.util.Scanner;
import java.lang.StringBuilder;
import java.lang.Math;
class TaxReturn
{
public static void main(String[] args)
{
String firstName, mI, lastName;
char M;
char S;
int SSN;
final int SSNLimit = 999999999;
int zip;
int income;
int pets;
int vehicle;
int toaster;
//Start string firstName
Scanner inputDevice = new Scanner(System.in);
System.out.print("First name: ");
firstName = inputDevice.next();
//Start middle name
System.out.print("Middle initial: ");
mI = inputDevice.next();
//Start lastName
System.out.print("Last name: ");
lastName = inputDevice.next();
//Start SSN (Social Security Number)
System.out.print("What is your Social Security Number?: ");
SSN = inputDevice.nextInt();
while(SSN > SSNLimit)
{
System.out.print("Invalid entry, please enter a valid Social Security Number");
System.out.print("\nPlease enter your Social again:");
SSN = inputDevice.nextInt();
}
}
}