3:Be sure that the id (index) of the added person is displayed on the screen.
5:Be sure that the size of the allPeople list does not change when a person's data is deleted.
6:Be sure that the -i argument displays the person's data.
package com.codegym.task.task17.task1710;
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<>();
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) throws ParseException {
// Start here
if (args[0].equals("-c")) {
if (args[2].equals("m")) {
allPeople.add(Person.createMale(args[1], new SimpleDateFormat("MM dd yyyy").parse(args[3])));
System.out.println(allPeople.size());
} else if (args[2].equals("f")) {
allPeople.add(Person.createFemale(args[1], new SimpleDateFormat("MM dd yyyy").parse(args[3])));
System.out.println(allPeople.size());
}
}
if (args[0].equals("-u")) {
int index = Integer.parseInt(args[1]);
allPeople.get(index).setName(args[2]);
allPeople.get(index).setBirthDate(new SimpleDateFormat("MM d yyyy").parse(args[4]));
if (args[3].equals("m")) {
allPeople.get(index).setSex(Sex.MALE);
} else if (args[3].equals("f")) {
allPeople.get(index).setSex(Sex.FEMALE);
}
}
if (args[0].equals("-d")) {
int index = Integer.parseInt(args[0]);
allPeople.get(index).setName(" ");
allPeople.get(index).setBirthDate(null);
allPeople.get(index).setSex(null);
}
if (args[0].equals("-i")) {
int index = Integer.parseInt(args[0]);
/*System.out.print(allPeople.get(index).getName() + " ");
System.out.print(allPeople.get(index).getSex() + " ");*/
String date = allPeople.get(index).getBirthDate().toString();
allPeople.get(index).setBirthDate(new SimpleDateFormat("MM dd yyyy",Locale.ENGLISH).parse(date));
System.out.println(allPeople.get(index));
}
}
}