commit eb320600e154389d828387d2e091cf208e2a1b9c Author: k-slonka Date: Mon Apr 13 20:33:14 2020 +0200 first commit diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..79a187d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/.idea/description.html b/.idea/description.html new file mode 100644 index 0000000..db5f129 --- /dev/null +++ b/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__aopalliance_aopalliance_1_0.xml b/.idea/libraries/Maven__aopalliance_aopalliance_1_0.xml new file mode 100644 index 0000000..30ff5cb --- /dev/null +++ b/.idea/libraries/Maven__aopalliance_aopalliance_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_beust_jcommander_1_72.xml b/.idea/libraries/Maven__com_beust_jcommander_1_72.xml new file mode 100644 index 0000000..ad12dd9 --- /dev/null +++ b/.idea/libraries/Maven__com_beust_jcommander_1_72.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_guava_guava_19_0.xml b/.idea/libraries/Maven__com_google_guava_guava_19_0.xml new file mode 100644 index 0000000..68e23cc --- /dev/null +++ b/.idea/libraries/Maven__com_google_guava_guava_19_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_google_inject_guice_no_aop_4_1_0.xml b/.idea/libraries/Maven__com_google_inject_guice_no_aop_4_1_0.xml new file mode 100644 index 0000000..d846de0 --- /dev/null +++ b/.idea/libraries/Maven__com_google_inject_guice_no_aop_4_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_inject_javax_inject_1.xml b/.idea/libraries/Maven__javax_inject_javax_inject_1.xml new file mode 100644 index 0000000..93cf65a --- /dev/null +++ b/.idea/libraries/Maven__javax_inject_javax_inject_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_13.xml b/.idea/libraries/Maven__junit_junit_4_13.xml new file mode 100644 index 0000000..59fc5c4 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_13.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_testng_testng_7_1_0.xml b/.idea/libraries/Maven__org_testng_testng_7_1_0.xml new file mode 100644 index 0000000..54dbda6 --- /dev/null +++ b/.idea/libraries/Maven__org_testng_testng_7_1_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_yaml_snakeyaml_1_21.xml b/.idea/libraries/Maven__org_yaml_snakeyaml_1_21.xml new file mode 100644 index 0000000..c86e780 --- /dev/null +++ b/.idea/libraries/Maven__org_yaml_snakeyaml_1_21.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0340661 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b6fec94 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/project-template.xml b/.idea/project-template.xml new file mode 100644 index 0000000..1f08b88 --- /dev/null +++ b/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..8db3a11 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,305 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1586462127137 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/filename.txt b/filename.txt new file mode 100644 index 0000000..97b0446 --- /dev/null +++ b/filename.txt @@ -0,0 +1 @@ +j j j 95070511101 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..69f0ba4 --- /dev/null +++ b/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + + groupId + untitled1 + 1.0-SNAPSHOT + + 1.8 + 1.8 + + + + + junit + junit + 4.12 + test + + + + org.testng + testng + RELEASE + test + + + junit + junit + 4.13 + test + + + + \ No newline at end of file diff --git a/src/main/java/com/company/AddToFile.java b/src/main/java/com/company/AddToFile.java new file mode 100644 index 0000000..33b0f6d --- /dev/null +++ b/src/main/java/com/company/AddToFile.java @@ -0,0 +1,41 @@ +package com.company; +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + +public class AddToFile { + public File createNewFile() throws IOException { + File file = new File("filename.txt"); + return file; + } + public void DeleteFile() { + File myObj = new File("filename.txt"); + myObj.delete(); + } + + public void addNewData(Person person, File file, List < String > listPesel) throws IOException { + boolean searchList = listPesel.contains(person.pesel); + if (searchList) { + int indexList = listPesel.indexOf(person.pesel); + Path path = Paths.get("filename.txt"); + List < String > lines = Files.readAllLines(path, StandardCharsets.UTF_8); + lines.set(indexList, person.city + " " + person.name + " " + person.surname + " " + person.pesel); + Files.write(path, lines, StandardCharsets.UTF_8); + } else { + try { + FileWriter myWriter = new FileWriter(file, true); + myWriter.write(person.city + " " + person.name + " " + person.surname + " " + person.pesel + "\n"); + myWriter.close(); + System.out.println("Dane dodano do bazy."); + listPesel.add(person.pesel); + } catch (IOException e) { + System.out.println("Nastapił bład przy zapisie."); + e.printStackTrace(); + } + + } + } +} \ No newline at end of file diff --git a/src/main/java/com/company/CheckPesel.java b/src/main/java/com/company/CheckPesel.java new file mode 100644 index 0000000..0360ed8 --- /dev/null +++ b/src/main/java/com/company/CheckPesel.java @@ -0,0 +1,21 @@ +package com.company; + +public class CheckPesel { + final char[] peselNumber; + + public CheckPesel(String pesel) { + peselNumber = pesel.toCharArray(); + } + + public boolean check(String pesel){ + final char[] peselNumber = pesel.toCharArray(); + if(pesel.length()==11){ + final int sumaKontrolna = 9*Integer.parseInt(String.valueOf(peselNumber[0])) + 7*Integer.parseInt(String.valueOf(peselNumber[1])) + 3*Integer.parseInt(String.valueOf(peselNumber[2])) + 1*Integer.parseInt(String.valueOf(peselNumber[3])) + 9*Integer.parseInt(String.valueOf(peselNumber[4])) + 7*Integer.parseInt(String.valueOf(peselNumber[5])) + 3*Integer.parseInt(String.valueOf(peselNumber[6])) + 1*Integer.parseInt(String.valueOf(peselNumber[7])) + 9*Integer.parseInt(String.valueOf(peselNumber[8])) + 7*Integer.parseInt(String.valueOf(peselNumber[9])); + if(sumaKontrolna%10!=Integer.parseInt(String.valueOf(peselNumber[10]))){ + return false; + }else{return true;} + }else{ + return false; + } + } +} diff --git a/src/main/java/com/company/Main.java b/src/main/java/com/company/Main.java new file mode 100644 index 0000000..16557ff --- /dev/null +++ b/src/main/java/com/company/Main.java @@ -0,0 +1,43 @@ +package com.company; + + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + + +public class Main { + + public static void main(String[] args) throws IOException { + int answer=1; + List listPesel = new ArrayList<>(); + + new AddToFile().DeleteFile(); + File fileName = new AddToFile().createNewFile(); + while (answer==1){ + final Scanner scan = new Scanner(System.in); + System.out.println("Podaj miasto"); + final String city = scan.nextLine(); + System.out.println("Podaj imie"); + final String name = scan.nextLine(); + System.out.println("Podaj nazwisko"); + final String surname = scan.nextLine(); + System.out.println("Podaj PESEL"); + final String pesel = scan.nextLine(); + Person person = new Person(city, name, surname, pesel); + CheckPesel chcek = new CheckPesel(pesel); + if(chcek.check(pesel)==true && person.checkPerson()==true){ + new AddToFile().addNewData(person,fileName,listPesel); + }else{ + System.out.println("Podano zły pesel lub nie podano wszytkich danych"); + } + System.out.println("Wpisz 1, jeśli chcesz dopisać kolejną osobę lub jakąkolwiek inna cyfre, aby zakonczyć"); + answer = scan.nextInt(); + + } + } + +} diff --git a/src/main/java/com/company/Person.java b/src/main/java/com/company/Person.java new file mode 100644 index 0000000..86301c6 --- /dev/null +++ b/src/main/java/com/company/Person.java @@ -0,0 +1,35 @@ +package com.company; + +public class Person { + String city; + String name; + String surname; + public String pesel; + + public Person(String city, String name, String surname, String pesel){ + this.city=city; + this.name=name; + this.surname=surname; + this.pesel=pesel; + } + + public boolean checkPerson(){ + if(city.isEmpty() || name.isEmpty() || surname.isEmpty() || pesel.isEmpty()){ + return false; + }else{ + return true; + }} + public String getPesel() { + return pesel; + } + public String getName() { return name; } + public String getSurname() { + return surname; + } + public String getCity() { + return city; + } + public String[] getPerson(){ + return new String[]{city, name, surname, pesel}; + } +} diff --git a/src/test/java/main/java/com/company/CheckPersonTest.java b/src/test/java/main/java/com/company/CheckPersonTest.java new file mode 100644 index 0000000..a20c17a --- /dev/null +++ b/src/test/java/main/java/com/company/CheckPersonTest.java @@ -0,0 +1,15 @@ +package main.java.com.company; + import com.company.Person; + import org.junit.Test; +import static org.junit.Assert.assertFalse; +public class CheckPersonTest { +Person person = new Person("", "name", "surname", "950707"); + Person person2 = new Person("", "", "surname", "950707"); + +@Test +public void checkPerson() { + assertFalse(person.checkPerson()); + + assertFalse(person2.checkPerson()); + } +} \ No newline at end of file diff --git a/src/test/java/main/java/com/company/CheckPeselTest.java b/src/test/java/main/java/com/company/CheckPeselTest.java new file mode 100644 index 0000000..ab43523 --- /dev/null +++ b/src/test/java/main/java/com/company/CheckPeselTest.java @@ -0,0 +1,18 @@ +package main.java.com.company; +import com.company.CheckPesel; +import com.company.Person; +import org.junit.Test; +import static org.junit.Assert.*; +public class CheckPeselTest { + + @Test + public void checkPesel() { + Person person = new Person("city", "name", "surname", "95070511123"); + Person person2 = new Person("city", "name", "surname", "950705"); + + CheckPesel chcek = new CheckPesel(person.pesel); + assertFalse(chcek.check(person.pesel)); + assertFalse(chcek.check(person2.pesel)); + + } +} \ No newline at end of file diff --git a/target/classes/com/company/AddToFile.class b/target/classes/com/company/AddToFile.class new file mode 100644 index 0000000..2497834 Binary files /dev/null and b/target/classes/com/company/AddToFile.class differ diff --git a/target/classes/com/company/CheckPesel.class b/target/classes/com/company/CheckPesel.class new file mode 100644 index 0000000..1e9a3ef Binary files /dev/null and b/target/classes/com/company/CheckPesel.class differ diff --git a/target/classes/com/company/Main.class b/target/classes/com/company/Main.class new file mode 100644 index 0000000..06e5d2e Binary files /dev/null and b/target/classes/com/company/Main.class differ diff --git a/target/classes/com/company/Person.class b/target/classes/com/company/Person.class new file mode 100644 index 0000000..e99d18f Binary files /dev/null and b/target/classes/com/company/Person.class differ diff --git a/target/test-classes/main/java/com/company/CheckPersonTest.class b/target/test-classes/main/java/com/company/CheckPersonTest.class new file mode 100644 index 0000000..6c2e284 Binary files /dev/null and b/target/test-classes/main/java/com/company/CheckPersonTest.class differ diff --git a/target/test-classes/main/java/com/company/CheckPeselTest.class b/target/test-classes/main/java/com/company/CheckPeselTest.class new file mode 100644 index 0000000..9184f19 Binary files /dev/null and b/target/test-classes/main/java/com/company/CheckPeselTest.class differ diff --git a/untitled1.iml b/untitled1.iml new file mode 100644 index 0000000..b55f154 --- /dev/null +++ b/untitled1.iml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file