public static void main(String[] args) {
   if (args[0].equals("-c")) {
     create(args);
   } else if (args[0].equals("-u")) {
     update(args);
   } else if (args[0].equals("-d")) {
     delete(args);
   } else if (args[0].equals("-i")) {
     select(args);
   } else {
     // return;
   }
   SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
   for (Person person : allPeople) {
     System.out.println(
         person.getName()
             + " "
             + (person.getSex().equals(Sex.MALE)
                 ? "м"
                 : (person.getSex().equals(Sex.FEMALE) ? "ж" : ""))
             + " "
             + ((person.getBirthDay() != null)
                 ? format.format(person.getBirthDay())
                 : person.getBirthDay()));
   }
 }
Beispiel #2
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    System.out.println("Hola Mundo");
    Person p1;
    Calendar f1;
    f1 = GregorianCalendar.getInstance();
    f1.set(1995, 5, 10);

    p1 = new Person("Roberto", "Diaz", f1);
    System.out.println(p1.getBirthDay());
    System.out.println(p1.getFullName());
    System.out.println(p1.getAge());
  }
  public static void select(String array[]) {

    Person person;
    int index;
    SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);

    for (int i = 1; i < array.length; i++) {
      index = Integer.parseInt(array[i]);
      if (index < allPeople.size()) {
        person = allPeople.get(index);
        System.out.println(
            person.getName()
                + " "
                + (person.getSex().equals(Sex.MALE)
                    ? "м"
                    : (person.getSex().equals(Sex.FEMALE) ? "ж" : ""))
                + " "
                + ((person.getBirthDay() != null)
                    ? format.format(person.getBirthDay())
                    : person.getBirthDay()));
      }
    }
  }
  public static void main(String[] args) throws ParseException {
    // start here - начни тут
    if (args.length < 2) return;

    if (args[0].equals("-c") && args.length >= 4) {
      Person person = null;
      int findIndex = 0;
      String name = "";
      for (int i = 1; i < args.length; i++) {
        if (args[i].equals("м") | args[i].equals("ж")) {
          findIndex = i;
          name = name.substring(0, name.length() - 1);
          break;
        } else {
          name = name + args[i] + " ";
        }
      }
      String sex = args[findIndex];
      Date bd = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse(args[findIndex + 1]);

      if (sex.equals("м")) person = Person.createMale(name, bd);
      if (sex.equals("ж")) person = Person.createFemale(name, bd);

      allPeople.add(person);

      System.out.println(allPeople.indexOf(person));
    }

    if (args[0].equals("-u") && args.length >= 5) {
      Person person = null;
      int id = Integer.parseInt(args[1]);
      int findIndex = 0;
      String name = "";
      for (int i = 2; i < args.length; i++) {
        if (args[i].equals("м") | args[i].equals("ж")) {
          findIndex = i;
          name = name.substring(0, name.length() - 1);
          break;
        } else {
          name = name + args[i] + " ";
        }
      }

      String sex = args[findIndex];
      Date bd = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse(args[findIndex + 1]);

      if (sex.equals("м")) person = Person.createMale(name, bd);
      if (sex.equals("ж")) person = Person.createFemale(name, bd);

      allPeople.set(id, person);
    }

    if (args[0].equals("-d") && args.length == 2) {
      int id = Integer.parseInt(args[1]);

      //            allPeople.remove(id);
      allPeople.set(id, null);
    }

    if (args[0].equals("-i") && args.length == 2) {
      int id = Integer.parseInt(args[1]);
      Person p = allPeople.get(id);
      String sex = null;
      String bd = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH).format(p.getBirthDay());

      if (p.getSex().equals(Sex.MALE)) sex = "м";
      if (p.getSex().equals(Sex.FEMALE)) sex = "ж";

      System.out.println(p.getName() + " " + sex + " " + bd);
    }
  }
 public static synchronized void UpdatePerson(int id, Person person) {
   Person per = allPeople.get(id);
   per.setName(person.getName());
   per.setSex(person.getSex());
   per.setBirthDay(person.getBirthDay());
 }
 public static void printInfo(Person person) {
   String sex = (person.getSex() == Sex.MALE) ? "м" : "ж";
   SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
   System.out.println(
       person.getName() + " " + sex + " " + simpleDateFormat.format(person.getBirthDay()));
 }