init
This commit is contained in:
commit
edf823884b
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.idea/
|
||||
|
||||
target/
|
2
ZJJXProjekt1.iml
Normal file
2
ZJJXProjekt1.iml
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4" />
|
23
pom.xml
Normal file
23
pom.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ZJJX-Projekt1</groupId>
|
||||
<artifactId>ZJJX-Projekt1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>13</source>
|
||||
<target>13</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
20
src/main/java/Main.java
Normal file
20
src/main/java/Main.java
Normal file
@ -0,0 +1,20 @@
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MM-yyyy HH-mm-ss");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String fileName = now.format(dtf) + " lista.txt";
|
||||
File file = new File(fileName);
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Read.read(file);
|
||||
}
|
||||
}
|
44
src/main/java/Pesel.java
Normal file
44
src/main/java/Pesel.java
Normal file
@ -0,0 +1,44 @@
|
||||
public class Pesel {
|
||||
protected static String pesel;
|
||||
|
||||
public static boolean checkPesel(String pesel) {
|
||||
Pesel.pesel = pesel;
|
||||
return (len() && checksum() && dayOfBirth());
|
||||
}
|
||||
|
||||
public static boolean checksum() {
|
||||
int[] multipliers = {1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1};
|
||||
int sum = 0;
|
||||
|
||||
for(int i = 0; i < 11; i++) {
|
||||
sum += multipliers[i] * Integer.valueOf(pesel.charAt(i));
|
||||
}
|
||||
|
||||
if(sum % 10 == 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean dayOfBirth() {
|
||||
String dayOfBirthStr = pesel.substring(4,6);
|
||||
int dayOfBirth = Integer.valueOf(dayOfBirthStr);
|
||||
if(dayOfBirth > 0 && dayOfBirth < 32) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean len() {
|
||||
if(pesel.length() == 11) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
42
src/main/java/Read.java
Normal file
42
src/main/java/Read.java
Normal file
@ -0,0 +1,42 @@
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Read {
|
||||
public static void read(File file) {
|
||||
String continuteInput;
|
||||
Scanner read = new Scanner(System.in);
|
||||
|
||||
while(true) {
|
||||
List<String> personalInfo = new ArrayList<String>();
|
||||
System.out.print("Podaj miasto: ");
|
||||
String city = read.nextLine();
|
||||
personalInfo.add(city);
|
||||
|
||||
System.out.print("Podaj imię, nazwisko, PESEL (oddzielone spacjami): ");
|
||||
String data = read.nextLine();
|
||||
for (String d : data.split(" ")) {
|
||||
personalInfo.add(d);
|
||||
}
|
||||
|
||||
if(!Pesel.checkPesel(personalInfo.get(3))) {
|
||||
System.out.println("Wprowadzony PESEL jest niepoprawny.");
|
||||
}
|
||||
else {
|
||||
boolean saved = false;
|
||||
// sprawdzenie czy już siedzi w pliku
|
||||
if(!saved) {
|
||||
Write.write(personalInfo, file);
|
||||
System.out.println("Osoba dodana do listy.");
|
||||
}
|
||||
}
|
||||
System.out.print("Chcesz kontynuować? [t/n] ");
|
||||
continuteInput = read.nextLine();
|
||||
if(continuteInput.equals("n")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
read.close();
|
||||
}
|
||||
}
|
35
src/main/java/Write.java
Normal file
35
src/main/java/Write.java
Normal file
@ -0,0 +1,35 @@
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
public class Write {
|
||||
public static void checkIfPeselExists(File file, List data) {
|
||||
if(file.exists()) {
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
|
||||
String line;
|
||||
while((line = bufferedReader.readLine()) != null) {
|
||||
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
System.out.println("Problem z odczytaniem danych z pliku.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void write(List data, File file) {
|
||||
if(file.exists()) {
|
||||
try (BufferedWriter fileWriter = new BufferedWriter(new FileWriter(file, true))){
|
||||
fileWriter.write(data.get(0) + " " + data.get(1) + " " + data.get(2) + " " + data.get(3) + "\n");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
System.out.println("Zapis danych do pliku zakończył się powodzeniem.");
|
||||
} else {
|
||||
System.out.println("Problem z zapisem do pliku.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user