This is what I have so far. What this program basically does is take user input(their social security numbers), verifies that their input is in the proper format (XXX-XX-XXXX), adds the verified input to the arrays list. Now the final step is to create a toString() method that will return a human readable String representation of all social security numbers added to the array. This method must use a for loop, and must print 1 social security number entry per line. For example:
"The Social Security Numbers you entered are:
345-43-5674
456-62-8435
910-70-0053"
package SSNServerStorage;
public class SSNArray
{
private String[] SSNNumber;
private int arrayCount;
public SSNArray(){
SSNNumber = new String[300];
arrayCount = 0;
}
public SSNArray(int arraySize){
SSNNumber = new String[arraySize];
arrayCount = 0;
}
public String[] getSSNNumber(){
return SSNNumber;
}
public int getArrayCount(){
return arrayCount;
}
public boolean validateSSNNumber(String SSNFormat){
return SSNFormat.matches("\\d{3}-\\d{2}-\\d{4}");
}
public String addSSN(String SSNFormat){
if (validateSSNNumber(SSNFormat)){
return SSNNumber[arrayCount++] = SSNFormat;
}else{
return null;
}
}
public String toString(){
System.out.println("The Social Security Numbers you entered are:");
for()
{
//
//
//
//
}
}
}
toStringmethod. That method should be used to create and return the String representation of an object, not print it.