Here is the Exact Instructions, but I have already done some of it. I will Write what I need help with at the bottom.
.I want to Write a program that reads in a social security number as a string (including the dashes) in the format DDD-DD-DDDD where D is a digit.
.I need to Write a method: public static boolean validSSN(String s)to check whether a string is in the format of DDD-DD-DDDD. Before I do anything I have to check the length of the input string.
.It should be 11 characters long(including the -'s) and anything else is invalid.
.I need to Write 2 boolean methods: isDigit(char c) and isDash(char c) to help check the format of the input and invoke them in the method body of validSSN.
.In the main method, I need to use a scanner object’s nextLine() method to read an entire line as a string invoke the validSSN method print the input and whether or not it is valid.
Here is what I have so far:
import java.util.Scanner;
public class lab14 {
public static void main(String[] args){
Scanner SSN = new Scanner(System.in);
System.out.println("Enter a Social Security Number");
int num = SSN.nextInt();
}
public static boolean validSSN(String s){
if
}
public static boolean isDigit(char c){
}
public static boolean isDash(char c){
}
}
So, I have written out the header for the main method, and the header for the boolean method that checks to see if there are 11 characters, a header for a boolean method that checks to see if the numbers are in the right place, and a header for a boolean method that checks to see if the dashes are in the right place. I have imported a Scanner method, and sent out for the user ti imput a social security number.
What I need help with is what to put in the body of each method. I need help to return true if there is 11 digits, if the numbers are in the right place, and if the dashes are in the right place. So If I were to input 123-56-7890, It would say that "123-56-7890 is a valid SSN", and I were to input 123/56/7890 or 123-567-890 it would say that ""123-567-890" or "123-567-890" is not a SSN". Can someone help me with verifying that the input is a SSN.