Пишет что проблемы с добавлением даты, может ее надо в определенном формате добавлять, не знаю..
package com.javarush.task.task17.task1710;
import org.w3c.dom.ls.LSOutput;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
/*
CRUD
*/
public class Solution {
public static 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 IOException, ParseException {
String[] subBegin = args.clone();
SimpleDateFormat inFormat = new SimpleDateFormat("dd/mm/yyyy");
SimpleDateFormat outFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
//СОЗДАНИЕ -c
if (subBegin[0].equals("-c")) {
if (subBegin[2].equals("м")) {
Date date = inFormat.parse(subBegin[3]);
String newDate = outFormat.format(date);
allPeople.add(Person.createMale(subBegin[1], outFormat.parse(newDate)));
System.out.println((allPeople.size() - 1));
}
else {
Date date = inFormat.parse(subBegin[3]);
String newDate = outFormat.format(date);
allPeople.add(Person.createFemale(subBegin[1], outFormat.parse(newDate)));
System.out.println(allPeople.size() - 1);
}
}
//ОБНОВЛЕНИЕ -u
if (subBegin[0].equals("-u")) {
if (subBegin[3].equals("м")) {
Date date = inFormat.parse(subBegin[4]);
String newDate = outFormat.format(date);
allPeople.get(Integer.parseInt(subBegin[1])).setSex(Sex.MALE);
allPeople.get(Integer.parseInt(subBegin[1])).setBirthDate(outFormat.parse(newDate));
allPeople.get(Integer.parseInt(subBegin[1])).setName(subBegin[2]);
}
else {
allPeople.remove(Integer.parseInt(subBegin[1]));
Date date = inFormat.parse(subBegin[3]);
String newDate = outFormat.format(date);
allPeople.get(Integer.parseInt(subBegin[1])).setSex(Sex.FEMALE);
allPeople.get(Integer.parseInt(subBegin[1])).setBirthDate(outFormat.parse(newDate));
allPeople.get(Integer.parseInt(subBegin[1])).setName(subBegin[2]);
}
}
//УДАЛЕНИЕ по id
if (subBegin[0].equals("-d")) {
allPeople.get(Integer.parseInt(subBegin[1])).setSex(null);
allPeople.get(Integer.parseInt(subBegin[1])).setName(null);
allPeople.get(Integer.parseInt(subBegin[1])).setBirthDate(null);
}
//INFO
if (subBegin[0].equals("-i")) {
Date soutDate = (allPeople.get(Integer.parseInt(subBegin[1])).getBirthDate());
String sosoutDate = outFormat.format(soutDate);
if (allPeople.get(Integer.parseInt(subBegin[1])).getSex() == Sex.MALE)
System.out.println(allPeople.get(Integer.parseInt(subBegin[1])).getName() + " м " +
sosoutDate);
else
System.out.println(allPeople.get(Integer.parseInt(subBegin[1])).getName() + " ж " +
sosoutDate);
}
}
}