Не могу понять, где проблема)
package com.javarush.task.task17.task1711;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/*
CRUD 2
*/
public class Solution {
public static volatile List<Person> allPeople = new ArrayList<Person>();
static {
allPeople.add(Person.createMale("Иванов Иван", new Date())); //сегодня родился id=0
allPeople.add(Person.createMale("Петров Петр", new Date())); //сегодня родился id=1
}
public static void main(String[] args) throws Exception {
SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy", Locale.ENGLISH);
SimpleDateFormat formatNew = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
String name;
Sex sex;
Date bd;
int id;
Person p;
switch (args[0]) {
case "-c": {
synchronized (allPeople) {
for (int i = 1; i < args.length; i = i + 3) {
name = args[i];
sex = (args[i + 1].equals("м")) ? Sex.MALE : Sex.FEMALE;
bd = format.parse(args[i + 2]);
if (sex == Sex.MALE) {
p = Person.createMale(name, bd);
} else {
p = Person.createFemale(name, bd);
}
allPeople.add(p);
System.out.println(allPeople.size()-1);
}
}
break;
}
case "-u": {
synchronized (allPeople) {
for (int i = 1; i < args.length; i = i + 4) {
id = Integer.parseInt(args[i]);
name = args[i + 1];
sex = (args[i + 2].equals("м")) ? Sex.MALE : Sex.FEMALE;
bd = format.parse(args[i + 3]);
p = allPeople.get(id);
p.setName(name);
p.setSex(sex);
p.setBirthDate(bd);
}
}
break;
}
case "-d": {
synchronized (allPeople) {
for (int i = 1; i < args.length; i++) {
id = Integer.parseInt(args[i]);
p = allPeople.get(id);
p.setName(null);
p.setBirthDate(null);
p.setSex(null);
}
}
break;
}
case "-i": {
synchronized (allPeople) {
for (int i = 1; i < args.length; i++) {
id = Integer.parseInt(args[i]);
p = allPeople.get(id);
if ((p.getSex() == Sex.MALE)) {
System.out.println(p.getName() + "м" + formatNew.format(p.getBirthDate()));
} else {
System.out.println(p.getName() + "ж" + format.format(p.getBirthDate()));
}
}
}
break;
}
}
}
}