Transformation of Java types



  • I've got data in this format at my entrance: -u id name sex bdid - number, name - name, sex - floor, bd - birthday.

    I have Class Personin 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's another one. Class Sex:

    public enum Sex {
    MALE,
    FEMALE
    }

    How do I get all the parameters from args to the designer? That's how it works:

    if (args[0].equals("-c")) {
    allPeople.add(new Person(args[1], Integer.valueOf(args[2]), args[3]));
    }



  • Each component of args transmitted to the main method has a type String.

    Stroke

    new Person(args[1], Integer.valueOf(args[2]), args[3])
    

    It doesn't make any sense. He doesn't have Person(String, Integer, String). That designer is private, and the code shows that it was planned to create copies through the design methods createMale and create Female.

    There is a clear need to create the necessary facilities. Sex - depending on the parameter value (between conditional expression, but can also be obtained through Enum.valueOf()), The date is SimpleDateFormat.

    I'd like to see the whole line of the challenge, because I don't know where it comes from.

    if (args[0].equals("-c"))
    

    When written

    I've got data in the program in this format: name sex bd


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2