First, you need to determine if the number of supplied arguments meet your expected needs...
// This assumes that address, city, country, home phone,
// office and cell phone are optional
if (args.length >= 3) {...
Or
// This assumes that all the values are required...
if (args.length >= 9) {...
If either of these cases are untrue (based on your needs), then you should display some kind of error message and probably exit...
You then need to extract the values from args
...
// This assumes that some of the arguments are optional...
String clientName = args[2];
String address = args.length > 3 ? args[3] : null;
String city = args.length > 4 ? args[4] : null;
String country = args.length > 5 ? args[5] : null;
String homePhone = args.length > 6 ? args[6] : null;
String officePhone = args.length > 7 ? args[7] : null;
String cellPhone = args.length > 8 ? args[8] : null;
Or
// This assumes that all the parameters are mandatory
String clientName = args[2];
String address = args[3];
String city = args[4];
String country = args[5];
String homePhone = args[6];
String officePhone = args[7];
String cellPhone = args[8];
Then create your Client
object...
Client client = new Client(
clientName,
address,
city,
country,
homePhone,
officePhone,
cellPhone);
This of course will mean that your Client
object will require a constructor capable of accepting the information your providing. Your example Client
won't work, apart from the fact that it has a Person
constructor which is invalid, it has no means to accept all this information...
public class Client{
private String ClientName;
private Address address;
private List<String> PhoneNumbers;
public Client() {
this.PhoneNumbers = new ArrayList<String>();
}
public Client(String clientName, String address, String city, String country, String homePhone, String officePhone, String cellPhone) {
this();
ClientName = clientName;
address = new Address(...); // No idea of the parameters for this...
AddPhoneNumber(homePhone);
AddPhoneNumber(officePhone);
AddPhoneNumber(cellPhone);
}
For example...