java - Return Multiple Arrays Using for Loop Inside toString Class -


this have far. program take user input(their social security numbers), verifies input in proper format (xxx-xx-xxxx), adds verified input arrays list. final step create tostring() method return human readable string representation of social security numbers added array. method must use loop, , must print 1 social security number entry per line. example:

"the social security numbers 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 entered are:");          for()         {             //             //             //             //         }     } } 

you can declare string concatenate ssnumbers.

@override public string tostring(){     string str = "the social security numbers entered are:\n";     for(int x=0; x< arraycount; x++)         str += ssnumber[x] + "\n";     return str; } 

since tostring() method, want return string representation of class instead of doing println().


Comments