I would appreciate the help here on what I am missing to pass the conditions.
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.length != 0){
switch (args[0]) {
case "-c":
Date date1 = new SimpleDateFormat("MMM dd yyyy", Locale.ENGLISH).parse(args[3]);
if (args[2].equals("m")) {
allPeople.add(Person.createMale(args[1], date1));
System.out.println(allPeople.size() - 1);
} else if(args[2].equals("f")) {
allPeople.add(Person.createFemale(args[1], date1));
System.out.println(allPeople.size() - 1);
}
break;
case "-u" :
Person updatePerson = allPeople.get(Integer.parseInt(args[1]));
Date date2 = new SimpleDateFormat("MMM dd yyy", Locale.ENGLISH).parse(args[3]);
updatePerson.setName(args[2]);
updatePerson.setBirthDate(date2);
if (args[3].equals("m")){
updatePerson.setSex(Sex.MALE);
} else {
updatePerson.setSex(Sex.FEMALE);
}
break;
case "-d" :
Person deletePerson = allPeople.get(Integer.parseInt(args[1]));
deletePerson.setName(null);
deletePerson.setSex(null);
deletePerson.setBirthDate(null);
break;
case "-i" :
Person infoPerson = allPeople.get(Integer.parseInt(args[1]));
System.out.println(infoPerson + " " + infoPerson.getSex() + " "
+ infoPerson.getBirthDate());
break;
default:
throw new IllegalStateException("Unexpected value: " + args[0]);
}
}
// if(args[0].equals("-c")) {
// SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy", Locale.ENGLISH);
// Date d = sdf.parse(args[3]);
// if(args[2].equals("m"))
// allPeople.add(Person.createMale(args[1], d));
// else
// allPeople.add(Person.createFemale(args[1], d));
// System.out.println(allPeople.size()-1);
// }
//
// else if(args[0].equals("-u")) {
// SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy", Locale.ENGLISH);
// Date d = sdf.parse(args[4]);
// Person person = allPeople.get(Integer.parseInt(args[1]));
// person.setName(args[2]);
// if(args[3].equals("m"))
// person.setSex(Sex.MALE);
// else
// person.setSex(Sex.FEMALE);
// person.setBirthDate(d);
// }
//
// else if(args[0].equals("-d")) {
// //allPeople.remove(Integer.parseInt(args[1]));
// Person person = allPeople.get(Integer.parseInt(args[1]));
// person.setName(null);
// person.setSex(null);
// person.setBirthDate(null);
// }
//
// else if(args[0].equals("-i")) {
// Person person = allPeople.get(Integer.parseInt(args[1]));
// String gender = "";
// if(person.getSex().equals(Sex.MALE))
// gender = "m";
// else
// gender = "f";
// System.out.print(person.getName() + " " + gender + " " + person.getBirthDate());
// }
}
}
"MM dd yyyy"(Correction: "MMM dd yyyy"). Set a SimpleDateFormatter as you did when reading in dates, and use it to output the date. It could be something like SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd yyyy", Locale.ENGLISH); And then maybe simpleDateFormat.format(infoPerson.getBirthDate()); All the best. ;-)