Last active
August 29, 2017 06:08
-
-
Save ihopeudie/90504909ac0f99c837d17b20bbc9d1e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.task.task17.task1711; | |
import java.text.SimpleDateFormat; | |
import java.util.ArrayList; | |
import java.util.Date; | |
import java.util.List; | |
import java.util.Locale; | |
/* | |
CRUD 2 javarush | |
-c name1 sex1 bd1 name2 sex2 bd2 ... | |
-u id1 name1 sex1 bd1 id2 name2 sex2 bd2 ... | |
-d id1 id2 id3 id4 ... | |
-i id1 id2 id3 id4 ... | |
*/ | |
public class Solution { | |
public static volatile List<Person> allPeople = new ArrayList<Person>(); | |
static { | |
allPeople.add(Person.createMale("Иванов Иван", new Date())); //сегодня родился id=0 | |
allPeople.add(Person.createMale("Петров Петр", new Date())); //сегодня родился id=1 | |
} | |
public static void main(String[] args) throws Exception { | |
//start here - начни тут | |
switch (args[0]) { | |
case "-c": { | |
// -c name1 sex1 bd1 name2 sex2 bd2 | |
synchronized (allPeople) { | |
int amount = (args.length - 1) / 3; | |
for (int i = 1; i < amount*3; i = i+3) { | |
Date date = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse(args[i + 2]); | |
if (args[i + 1].equals("м")) allPeople.add(Person.createMale(args[i], date)); | |
else allPeople.add(Person.createFemale(args[i], date)); | |
System.out.println(allPeople.size() - 1); | |
} | |
break; | |
} | |
} | |
case "-d": { | |
synchronized (allPeople) { | |
int amount = (args.length - 1); | |
for (int i = 1; i < amount+1; i++) { | |
allPeople.get(Integer.parseInt(args[i])).setName(null); | |
allPeople.get(Integer.parseInt(args[i])).setSex(null); | |
allPeople.get(Integer.parseInt(args[i])).setBirthDay(null); | |
} | |
break; | |
} | |
} | |
case "-u": { | |
synchronized (allPeople) { | |
// -u id name sex bd | |
int amount = (args.length - 1) / 4; | |
for (int i = 1; i < amount*4; i += 4) { | |
Date date = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH).parse(args[i + 3]); | |
Person upd; | |
if (args[i + 2].equals("м")) { | |
upd = Person.createMale(args[i + 1], date); | |
} else upd = Person.createFemale(args[i + 1], date); | |
allPeople.set(Integer.parseInt(args[i]), upd); | |
} | |
break; | |
} | |
} | |
case "-i": { | |
synchronized (allPeople) { | |
int amount = (args.length - 1); | |
String sex = new String(); | |
for (int i = 1; i < amount + 1; i++) { | |
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH); | |
String sDate = sdf.format(allPeople.get(Integer.parseInt(args[i])).getBirthDay()); | |
if (allPeople.get(Integer.parseInt(args[i])).getSex() == Sex.MALE) sex = "м"; | |
else sex = "ж"; | |
System.out.println(allPeople.get(Integer.parseInt(args[i])).getName() + " " + sex + " " + sDate); | |
} | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment