not the cleanest code i ever made but the logic seems correct to me
package com.codegym.task.task17.task1710;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/*
CRUD
*/
public class Solution {
public static List<Person> allPeople = new ArrayList<>();
static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
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 IOException, ParseException {
String input = reader.readLine();
String[] inputs = input.split(" ", 4);
switch (inputs[0]) {
case "-c":
Date birthDate = new SimpleDateFormat("MM dd yy").parse(inputs[3].substring(1, inputs[3].length() - 1));
if (inputs[2].equals("m")) {
allPeople.add(Person.createMale(inputs[1], birthDate));
System.out.println(allPeople.size() - 1);
} else if (inputs[2].equals("f")) {
allPeople.add(Person.createFemale(inputs[1], birthDate));
System.out.println(allPeople.size() - 1);
}
break;
case "-u":
Person person = allPeople.get(Integer.parseInt(inputs[1]));
Date birthDate1 = new SimpleDateFormat("MM dd yy").parse(inputs[4].substring(1, inputs[4].length() - 1));
person.setBirthDate(birthDate1);
person.setName(inputs[2]);
if (inputs[3].equals("m")) {
person.setSex(Sex.MALE);
} else {
person.setSex(Sex.FEMALE);
}
break;
case "-d":
Person person1 = allPeople.get(Integer.parseInt(inputs[1]));
person1.setSex(null);
person1.setName(null);
person1.setBirthDate(null);
break;
case "-i":
Person person2 = allPeople.get(Integer.parseInt(inputs[1]));
System.out.print(person2.getName() + " ");
if (person2.getSex().equals(Sex.MALE)) {
System.out.print("m ");
} else {
System.out.print("f ");
}
System.out.print(theMonth(person2.getBirthDate().getMonth()) + " ");
System.out.print(person2.getBirthDate().getDay() + " ");
System.out.println(person2.getBirthDate().getYear() + 1900);
break;
}
}
public static String theMonth(int month) {
String[] monthNames = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
return monthNames[month];
}
}