Otrzymuje ten komunikat:
Upewnij się, że metoda main posiada wyrażenie switch oparte o args[0].
It receives this message:
Make sure the main method has a switch expression based on args[0].
package pl.codegym.task.task17.task1711;
import java.text.DateFormat;
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 2
*/
public class Solution {
public static volatile 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 {
// Zacznij tutaj
switch (args[0]) {
case ("-c"):
for (int i = 1; i < args.length; i+=3){
createPeople(args, i);
}
break;
case ("-u"):
for (int i = 1; i < args.length; i+=4){
updatePeople(args, i);
}
break;
case ("-d"):
int x = 1;
while (x < args.length){
deletePerson(args, x);
x++;
}
break;
case ("-i"):
printPerson(args);
break;
default:
System.out.println("Error: Wrong basic parameter, typing: -c,-u,-d or -i");
}
}
public static synchronized void createPeople (String[] strings, int i) throws ParseException {
String name = strings[i];
String gender = strings[i+1];
String birdhDay = strings[i+2];
String pattern = "MM dd yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.ENGLISH);
Date dateformat = sdf.parse(birdhDay);
if (gender.equals("m")){
allPeople.add(Person.createMale(name,dateformat));
} else if (gender.equals("f")) {
allPeople.add(Person.createFemale(name,dateformat));
}
System.out.println(allPeople.size()-1);
}
public static synchronized void updatePeople (String[] strings, int i) throws ParseException {
int id = Integer.parseInt(strings[i]);
allPeople.get(id).setName(strings[i+1]);
String gender = strings[i+2];
if (gender.equals("m")) {
allPeople.get(id).setSex(Sex.MALE);
} else if (gender.equals("f")) {
allPeople.get(id).setSex(Sex.FEMALE);
}
String pattern = "MM dd yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(pattern, Locale.ENGLISH);
Date dateformat = sdf.parse(strings[i+3]);
allPeople.get(id).setBirthDate(dateformat);
}
public static synchronized void deletePerson (String[] strings, int i){
int id = Integer.parseInt(strings[i]);
allPeople.get(id).setName(null);
allPeople.get(id).setSex(null);
allPeople.get(id).setBirthDate(null);
}
public static synchronized void printPerson (String[] strings){
for (int i = 1; i < strings.length; i++)
{
SimpleDateFormat formatter = new SimpleDateFormat("MMM dd yyyy", Locale.ENGLISH);
Person person = allPeople.get(Integer.parseInt(strings[i]));
if (person.getSex().equals(Sex.MALE)) {
System.out.println(person.getName() + " m " + formatter.format(person.getBirthDate()));
} else {
System.out.println(person.getName() + " f " + formatter.format(person.getBirthDate()));
}
}
}
}