last condition is not verifying :(
package com.codegym.task.task17.task1710;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.text.*;
/*
CRUD
1. The Solution class must contain a public static List<Person> field called allPeople.
2. The Solution class must have a static block where two people are added to the allPeople list.
3. When you start the program with the -c argument, the program should add the person with the specified arguments to the end of the allPeople list and display the id (index).
4. When you run the program with the -u argument, the program must update the data of the person with the specified id in the allPeople list.
5. When you run the program with the -d argument, the program must perform the logical deletion the person with the specified id in the allPeople list.
6. When you run the program with the -i argument, the program should display the data about the person with the specified id in accordance with the format given in the task.
*/
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{
if (args[0].equals("-c")) {
String name = args[1];
Date date = new SimpleDateFormat("MM dd yyyy", Locale.ENGLISH).parse(args[3]);
if (args[2].equals("m")) {
allPeople.add(Person.createMale(name, date));
} else {
allPeople.add(Person.createFemale(name, date));
}
System.out.println(allPeople.size() - 1);
}
if (args[0].equals("-u")) {
String name = args[2];
// for (Person allPerson : allPeople) {
Person allPerson = allPeople.get(Integer.parseInt(args[1]));
Date date = new SimpleDateFormat("MM dd yyyy", Locale.ENGLISH).parse(args[4]);
allPerson.setName(name);
allPerson.setBirthDate(date);
if (args[3].equals("m")) {
allPerson.setSex(Sex.MALE);
} else if (args[3].equals("f")) {
allPerson.setSex(Sex.FEMALE);
}
}
if (args[0].equals("-d")) {
String name = null;
//SimpleDateFormat date = new SimpleDateFormat("MM DD YYYY", Locale.ENGLISH).parse(null);
for (Person allPerson : allPeople) {
allPerson.setName(name);
allPerson.setBirthDate(null);
allPerson.setSex(null);
}
}
if (args[0].equals("-i")) {
for (Person allPerson : allPeople) {
String name = args[1];
allPerson.setName(name);
if (args[2].equals("m")) {
allPerson.setSex(Sex.MALE);
} else if (args[2].equals("f")) {
allPerson.setSex(Sex.FEMALE);
}
SimpleDateFormat date = new SimpleDateFormat("MMM dd yyyy", Locale.ENGLISH);
System.out.println(date.format(allPerson.getBirthDate()));
}
}
}
}