int id = Integer.parseInt(args[1]);
как из "name" получается id? кроме
allPeople.add(Person.createMale("Иванов Иван", new Date()));
нигде не слова про id
case "-u":
birthdayDate = simpleDateFormat.parse(args[4]);
почему дата стала 4 параметром, была же третьим
полный код
при параметрах -i Миронов м 15/04/1990 экспешн (скриншот) строка 70
person=allPeople.get(Integer.parseInt(args[1]));
public class Solution {
public static List<Person> allPeople = new ArrayList<Person>();
static {
allPeople.add(Person.createMale("Иванов Иван", new Date()));
allPeople.add(Person.createMale("Петров Петр", new Date()));
}
static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH);
static SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
public static void main(String[] args) throws Exception {
if (args == null || args.length < 1)
throw new RuntimeException();
Date birthdayDate;
Person person;
switch (args[0]) {
case "-c":
birthdayDate=simpleDateFormat.parse(args[3]);
if(args[2].equals("м")) {
person=Person.createMale(args[1], birthdayDate);
}
else {
person= Person.createFemale(args[1], birthdayDate);
}
allPeople.add(person);
System.out.println(allPeople.size()-1);
break;
case "-u":
person=allPeople.get(Integer.parseInt(args[1]));
if (person ==null) {
throw new InterruptedException();
}
else {
int id=Integer.parseInt(args[1]);
birthdayDate=simpleDateFormat.parse(args[4]);
person.setBirthDate(birthdayDate);
if(args[3].equals("м")) {
person.setSex(Sex.MALE);
}
else {
person.setSex(Sex.FEMALE);
}
person.setName(String.valueOf(args[2]));
allPeople.set(id,person);
}
break;
case "-d":
person=allPeople.get(Integer.parseInt(args[1]));
person.setName(null);
person.setSex(null);
person.setBirthDate(null);
break;
case "-i":
person=allPeople.get(Integer.parseInt(args[1]));
person.setBirthDate(simpleDateFormat2.parse(args[3]));
if(person != null)
System.out.println(person.getName() + (person.getSex().equals(Sex.FEMALE) ? "ж":"м") + person.getBirthDate());
break;
}
}
}