I don't understand this at all. When you remove something from an ArrayList, the size of the ArrayList is going to go down. What exactly is it asking me to do?
package com.codegym.task.task17.task1710;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
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<>();
static
{
allPeople.add(Person.createMale("Donald Chump", new Date())); // id=0
allPeople.add(Person.createMale("Larry Gates", new Date())); // id=1
}
public static void main(String[] args)
{
Date readDate;
SimpleDateFormat formatter = new SimpleDateFormat("MM dd yyyy", Locale.ENGLISH);
switch(args[0])
{
case "-c":
try
{
readDate = formatter.parse(args[3]);
if(args[2].equals("m"))
{
allPeople.add(Person.createMale(args[1], readDate));
}
else
{
allPeople.add(Person.createFemale(args[1], readDate));
}
System.out.println(allPeople.size()-1);
}
catch(ParseException e)
{
}
break;
case "-u":
try
{
readDate = formatter.parse(args[4]);
allPeople.get(Integer.parseInt(args[1])).setName(args[2]);
if(args[3].equals("m"))
{
allPeople.get(Integer.parseInt(args[1])).setSex(Sex.MALE);
}
else
{
allPeople.get(Integer.parseInt(args[1])).setSex(Sex.FEMALE);
}
allPeople.get(Integer.parseInt(args[1])).setBirthDate(readDate);
}
catch(ParseException e)
{
}
break;
case "-d":
allPeople.remove(Integer.parseInt(args[1]));
break;
case "-i":
SimpleDateFormat outFormat = new SimpleDateFormat("MMM dd yyyy", Locale.ENGLISH);
String outDate = outFormat.format(allPeople.get(Integer.parseInt(args[1])).getBirthDate());
String sex = "";
if(allPeople.get(Integer.parseInt(args[1])).getSex() == Sex.MALE)
{
sex = "m";
}
else
{
sex = "f";
}
System.out.println(allPeople.get(Integer.parseInt(args[1])).getName() + " " + sex + " " + outDate);
break;
}
}
}