At the entrance of my program receives data in this format: -u id name sex bd . id - number, name - name, sex - sex, bd - birthday.
I have a Person class in which all these values are added:
public class Person { private String name; private Sex sex; private Date birthDay; private Person(String name, Sex sex, Date birthDay) { this.name = name; this.sex = sex; this.birthDay = birthDay; } public static Person createMale(String name, Date birthDay){ return new Person(name, Sex.MALE, birthDay); } public static Person createFemale(String name, Date birthDay){ return new Person(name, Sex.FEMALE, birthDay); } public String getName() { return name; } public void setName(String name) { this.name = name; } public Sex getSex() { return sex; } public void setSex(Sex sex) { this.sex = sex; } public Date getBirthDay() { return birthDay; } public void setBirthDay(Date birthDay) { this.birthDay = birthDay; } } There is such a class Sex :
public enum Sex { MALE, FEMALE } How do I pass all the parameters from args to the constructor? This is how this is understandably not working:
if (args[0].equals("-c")) { allPeople.add(new Person(args[1], Integer.valueOf(args[2]), args[3])); }