Решение пунктов всех получилось, кроме чтения.
Я уже и так и так, но никак не получается пройти 4 пункт валидатора.
package com.javarush.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<Person>();
static {
allPeople.add(Person.createMale("Иванов Иван", new Date())); //сегодня родился id=0
allPeople.add(Person.createMale("Петров Петр", new Date())); //сегодня родился id=1
}
static SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH);
static SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
public static void main(String[] args) {
//start here - начни тут
String name,
command = "";
char sex;
Date birthday = null;
int id = 0;
Person person = null;
String personSex = "";
//String pattern1 = "dd/MM/yyyy";
//String pattern2 = "d-MMM-YYYY";
//SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(pattern1, Locale.ENGLISH);
//SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat(pattern2, Locale.ENGLISH);
try {
command = args[0];
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println("Пустой массив args[]");
}
//catch (Ou)
switch (command){
case "-c":
name = args[1];
sex = args[2].charAt(0);
try{
birthday = simpleDateFormat1.parse(args[3]);
}
catch (ParseException e){
e.printStackTrace();
}
if (sex == 'м')
allPeople.add(Person.createMale(name, birthday));
if (sex == 'ж')
allPeople.add(Person.createFemale(name, birthday));
System.out.println(allPeople.size() - 1);
break;
case "-i":
id = Integer.parseInt(args[1]);
//printInfo(id);
person = allPeople.get(id);
personSex = (person.getSex() == Sex.MALE ? "м" : "ж");
if (person.getSex() == Sex.MALE) personSex = "м";
if (person.getSex() == Sex.FEMALE) personSex = "ж";
if (person.getSex() == null) personSex = null;
/* try{
birthday = simpleDateFormat1.parse("15/04/1990");
}
catch (ParseException e){
e.printStackTrace();
}
if (personSex == "м")
allPeople.set(id, Person.createMale(person.getName(), birthday));
if (personSex == "ж")
allPeople.set(id, Person.createFemale(person.getName(), birthday));
person = allPeople.get(id);*/
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
//Person person = allPeople.get(Integer.parseInt(args[1]));
String bd = dateFormat.format(person.getBirthDate());
/* String s = "";
try{
s = simpleDateFormat2.format(person.getBirthDate());
}
catch (NullPointerException e){
s = null;
}*/
System.out.println(person.getName() + " " +
personSex + " " +
/*s*/
bd);
//printInfo(id);
break;
case "-u":
id = Integer.parseInt(args[1]);
//printInfo(id);
name = args[2];
sex = args[3].charAt(0);
try{
birthday = simpleDateFormat1.parse(args[4]);
}
catch (ParseException e){
e.printStackTrace();
}
if (sex == 'м')
allPeople.set(id, Person.createMale(name, birthday));
if (sex == 'ж')
allPeople.set(id, Person.createFemale(name, birthday));
/* System.out.println();
System.out.println(id);
printInfo(id);
printInfo(0);
printInfo(1);*/
break;
case "-d":
person = Person.createMale(null, null);
person.setSex(null);
id = Integer.parseInt(args[1]);
//printInfo(id);
allPeople.set(id, person);
break;
default:
System.out.println("Команда не распознана!");
break;
}
System.out.println();
}
/*public static void printInfo(int id){
Person person = allPeople.get(id);
String personSex = (person.getSex() == Sex.MALE ? "м" : "ж");
if (person.getSex() == Sex.MALE) personSex = "м";
if (person.getSex() == Sex.FEMALE) personSex = "ж";
if (person.getSex() == null) personSex = null;
String s = "";
try{
s = simpleDateFormat2.format(person.getBirthDate());
}
catch (NullPointerException e){
s = null;
}
System.out.println(person.getName() + " " +
personSex + " " +
s);
}*/
}