Help me
package com.codegym.task.task17.task1711;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.io.*;
/*
CRUD
*/
public class Solution {
public volatile 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 Exception{
switch (args[0]){
case "-c":
synchronized (allPeople) {
int numberOfPeople = (args.length - 1) / 3;
String[][] peoples = new String[numberOfPeople][3];
for (int i = 0; i < peoples.length; i++) {
String[] people = peoples[i];
people[0] = args[3 * i + 1];
people[1] = args[3 * i + 2];
people[2] = args[3 * i + 3];
}
String name = null;
String sex = null;
String bd = null;
Date date = null;
for (int i = 0; i < peoples.length; i++) {
name = peoples[i][0];
sex = peoples[i][1];
bd = peoples[i][2];
date = new SimpleDateFormat("MM dd yyyy", Locale.ENGLISH).parse(bd);
switch (sex) {
case "m":
allPeople.add(Person.createMale(name, date));
break;
case "f":
allPeople.add(Person.createFemale(name, date));
break;
}
System.out.println(allPeople.size() - 1);
}
}
break;
case "-u":
synchronized (allPeople){
int numberOfPeople = (args.length - 1)/4;
String[][] peoples = new String[numberOfPeople][4];
for (int i = 0; i < peoples.length; i++) {
String[] people = peoples[i];
people[0] = args[4*i + 1];
people[1] = args[4*i + 2];
people[2] = args[4*i + 3];
people[3] = args[4*i + 4];
}
int id = 0;
Person person = null;
for (int i = 0; i < peoples.length; i++) {
id = Integer.parseInt(peoples[i][0]);
String name = peoples[i][1];
String sex = peoples[i][2];
String bd = peoples[i][3];
Date date = new SimpleDateFormat("MM dd yyyy", Locale.ENGLISH).parse(bd);
person = allPeople.get(id);
person.setName(name);
person.setBirthDate(date);
switch(sex){
case "m":
person.setSex(Sex.MALE);
break;
case "f":
person.setSex(Sex.FEMALE);
break;
}
}
break;}
case "-d":
synchronized (allPeople){
int numberOfPeople = args.length - 1;
String[] idList = new String[numberOfPeople];
for (int i = 0; i < idList.length; i++) {
idList[i] = args[i + 1];
}
for (int i = 0; i < idList.length; i++) {
int id = Integer.parseInt(idList[i]);
Person person = allPeople.get(id);
person.setSex(null);
person.setBirthDate(null);
person.setName(null);
}
break;}
case "-i":
synchronized (allPeople){
int numberOfPeople = args.length - 1;
String[] idList = new String[numberOfPeople];
for (int i = 0; i < idList.length; i++) {
idList[i] = args[i + 1];
}
for (int i = 0; i < idList.length; i++) {
int id = Integer.parseInt(idList[i]);
Person person = allPeople.get(id);
System.out.print(person.getName() + " ");
switch (person.getSex()){
case MALE:
System.out.print("m ");
break;
case FEMALE:
System.out.print("f ");
break;
}
System.out.println(new SimpleDateFormat("MMM dd yyyy", Locale.ENGLISH).format(person.getBirthDate()));
}
break;}
}
}
}