From d858ff8f8dca2f08a89dc59a6bc3d771204679ed Mon Sep 17 00:00:00 2001 From: pbg2h21ama Date: Mon, 16 Jan 2023 16:53:30 +0100 Subject: [PATCH 1/8] =?UTF-8?q?Methode=20validateData=20erg=C3=A4nzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Data.java | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/Data.java b/src/Data.java index 27a46ef..8c5a40f 100644 --- a/src/Data.java +++ b/src/Data.java @@ -5,6 +5,9 @@ import java.nio.file.Paths; import java.sql.Array; import java.util.ArrayList; import java.util.List; +import java.util.Scanner; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Data is a class to edit files. @@ -223,5 +226,70 @@ public class Data { } return rows; } + + /** + * The method validates the user input + * + * @return boolean inputValid + * @author Kevin Maier + */ + private boolean validateData(String password, String phoneNumber) + { + boolean inputValid = false; + boolean phoneNumberMatchFound; + boolean passwordMatchFound; + boolean phoneNumberValid = false; + boolean passwordValid = false; + + Pattern phoneNumberPattern = Pattern.compile("[0-9]*"); + Pattern passwordPattern = Pattern.compile("^[^a-zA-Z0-9].*[0-9]$"); + + Scanner reader = new Scanner(System.in); + + while(password.isEmpty() || phoneNumber.isEmpty()) + { + System.out.println("Login fehlgeschlagen. Eingabe ist leer, versuchen Sie es erneut."); + System.out.println(""); + System.out.print("Telefonnummer: "); + phoneNumber = reader.nextLine(); + System.out.print("Passwort: "); + password = reader.nextLine(); + } + + Matcher phoneNumberMatcher = phoneNumberPattern.matcher(phoneNumber); + Matcher passwordMatcher = passwordPattern.matcher(password); + + phoneNumberMatchFound = phoneNumberMatcher.find(); + passwordMatchFound = passwordMatcher.find(); + + while (!inputValid) { + if (!phoneNumberMatchFound || phoneNumber.length() != 15) { + System.out.println("Login fehlgeschlagen. Die eingegebene Handynummer ist nicht valide."); + System.out.println(""); + System.out.print("Telefonnummer: "); + phoneNumber = reader.nextLine(); + System.out.print("Passwort: "); + password = reader.nextLine(); + } else { + phoneNumberValid = true; + } + + if (!passwordMatchFound || password.length() < 6 || password.length() > 20) { + System.out.println("Login fehlgeschlagen. Das eingegebene Passwort ist nicht valide."); + System.out.println(""); + System.out.print("Telefonnummer: "); + phoneNumber = reader.nextLine(); + System.out.print("Passwort: "); + password = reader.nextLine(); + } else { + passwordValid = true; + } + + if (phoneNumberValid && passwordValid) { + inputValid = true; + } + } + return inputValid; + } } From d2f9ef49c98469f92bf503139f426b9a7aff7c6a Mon Sep 17 00:00:00 2001 From: Felix Woestemeyer Date: Tue, 17 Jan 2023 15:43:56 +0100 Subject: [PATCH 2/8] =?UTF-8?q?Korrektur=20der=20Syntax=20und=20einhaltlic?= =?UTF-8?q?he=20toString=20f=C3=BCr=20das=20Speichern=20der=20Daten.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Data.java | 8 +++++--- src/Menu.java | 21 ++++++++++----------- src/Order.java | 15 ++++++++++----- src/User.java | 11 ++--------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/Data.java b/src/Data.java index 8c5a40f..8028ac5 100644 --- a/src/Data.java +++ b/src/Data.java @@ -188,9 +188,9 @@ public class Data { String date = parts[0]; String user = parts[1]; - String mealtyp = parts[3]; - String deserttyp = parts[5]; - orderList.add(new Order(date, user, mealtyp, deserttyp)); + String mealtype = parts[3]; + String deserttype = parts[5]; + orderList.add(new Order(date, user, mealtype, deserttype)); } return null;//orderList @@ -207,6 +207,8 @@ public class Data { } else if (pathWrite.equals("orders.txt")) { + } else if (pathWrite.equals("menue.txt")){ + } } diff --git a/src/Menu.java b/src/Menu.java index 71ac4f6..99276d2 100644 --- a/src/Menu.java +++ b/src/Menu.java @@ -10,7 +10,7 @@ public class Menu { String date; String dish; String sideDish; - String typ; + String type; List ingredients; @@ -20,14 +20,14 @@ public class Menu { * @param date date of meal * @param dish meal * @param sideDish side dish - * @param typ vegan, vegetarian or meat + * @param type vegan, vegetarian or meat * @param ingredients list of ingredients */ - public Menu(String date, String dish, String sideDish, String typ, List ingredients) { + public Menu(String date, String dish, String sideDish, String type, List ingredients) { this.date = date; this.dish = dish; this.sideDish = sideDish; - this.typ = typ; + this.type = type; this.ingredients = ingredients; } @@ -47,26 +47,25 @@ public class Menu { * @return typ e.g. Vegan * @author Madeleine Vigier */ - public String getTyp() { - if (typ.contains("DessertV") || typ.contains("Dessert")) { + public String getType() { + if (type.contains("DessertV") || type.contains("Dessert")) { return ""; } else { - return typ; + return type; } } /** - * The method toString() returns a String representation of an object + * The method toString() returns a String formated to save in a File * * @return a String with dish, sideDish, list of ingredients and the typ of the menu - * @author Madeleine Vigier + * @author Madeleine Vigier, Felix Wöstemeyer */ @Override public String toString() { - return dish + "\n" + sideDish - + "\n" + ingredients.toString().replace("[", "").replace("]", "") + "\n" + getTyp() + "\n"; + return date+";"+dish+";"+sideDish+";"+type+";"+ingredients; } } diff --git a/src/Order.java b/src/Order.java index 525317a..ce80745 100644 --- a/src/Order.java +++ b/src/Order.java @@ -8,14 +8,19 @@ public class Order { String date; //date for the meal, not the day it was ordered String user; //phone number of the user account - String mealtyp; //meat, vegi or vegan - String deserttyp; //desert or vegan desert + String mealtype; //meat, vegi or vegan + String desserttype; //desert or vegan desert - Order (String date, String user, String mealtyp, String deserttyp) + Order (String date, String user, String mealtype, String desserttype) { this.date = date; this.user = user; - this.mealtyp = mealtyp; - this.deserttyp = deserttyp; + this.mealtype = mealtype; + this.desserttype = desserttype; + } + + @Override + public String toString(){ + return date+";"+user+";"+mealtype+";"+desserttype; } } diff --git a/src/User.java b/src/User.java index a569f70..a44bea9 100644 --- a/src/User.java +++ b/src/User.java @@ -19,7 +19,7 @@ public class User { * @param nameParent2 name of the second parent of the child * @param billAddress the address the bill should be sent to * @param phoneNumber phonenumber of one of the parents and also the username - * @param nameChildren name of the child + * @param nameChildren name of the children * @param password password of the user * @author Madeleine Vigier */ @@ -80,13 +80,6 @@ public class User { */ @Override public String toString() { - return "User{" + - "nameParent1='" + nameParent1 + '\'' + - ", nameParent2='" + nameParent2 + '\'' + - ", billAddress='" + billAddress + '\'' + - ", phonenumber='" + phoneNumber + '\'' + - ", nameChildren='" + nameChildren + '\'' + - ", password='" + password + '\'' + - '}'; + return nameParent1 + ";" + nameParent2 + ";" + billAddress + ";" + phoneNumber + ";" + nameChildren + ";" + password; } } From 83af3a6066a654e4840f83b41adc071926babc05 Mon Sep 17 00:00:00 2001 From: pbg2h21ama Date: Tue, 17 Jan 2023 16:02:29 +0100 Subject: [PATCH 3/8] =?UTF-8?q?Regex=20in=20validateData=20ge=C3=A4ndert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Data.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data.java b/src/Data.java index 8c5a40f..3ba410c 100644 --- a/src/Data.java +++ b/src/Data.java @@ -242,7 +242,7 @@ public class Data { boolean passwordValid = false; Pattern phoneNumberPattern = Pattern.compile("[0-9]*"); - Pattern passwordPattern = Pattern.compile("^[^a-zA-Z0-9].*[0-9]$"); + Pattern passwordPattern = Pattern.compile("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$"); Scanner reader = new Scanner(System.in); From 3df13417c7b103fb7c2bc50fe311eb1d9092f210 Mon Sep 17 00:00:00 2001 From: Felix Woestemeyer Date: Tue, 17 Jan 2023 16:09:55 +0100 Subject: [PATCH 4/8] =?UTF-8?q?Korrektur=20der=20Syntax=20und=20einhaltlic?= =?UTF-8?q?he=20toString=20f=C3=BCr=20das=20Speichern=20der=20Daten.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Data.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Data.java b/src/Data.java index 8028ac5..f39a587 100644 --- a/src/Data.java +++ b/src/Data.java @@ -1,8 +1,9 @@ +import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.sql.Array; import java.util.ArrayList; import java.util.List; import java.util.Scanner; @@ -199,16 +200,20 @@ public class Data { /** * The method writeData writes the data of a List into a txt file. * + * @author Felix Wöstemeyer + * * @param pathWrite determines the filename of the file that will be written * @param listToWrite determines which ArrayList is to be used for writing the file */ public void writeData(String pathWrite, ArrayList listToWrite) { - if (pathWrite.equals("users.txt")) { - - } else if (pathWrite.equals("orders.txt")) { - - } else if (pathWrite.equals("menue.txt")){ - + try { + if (new File(pathWrite).exists()) { + for (String zeile : listToWrite) { + new FileWriter(pathWrite).write(zeile); + } + } + }catch(IOException e){ + e.printStackTrace(); } } From a44c87cf831108845f8e9682e823e1387c8ee397 Mon Sep 17 00:00:00 2001 From: pbg2h21ama Date: Tue, 17 Jan 2023 16:15:58 +0100 Subject: [PATCH 5/8] =?UTF-8?q?isEmpty=20Abfrage=20entfernt=20und=20in=20v?= =?UTF-8?q?alidData=20Methode=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Login.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Login.java b/src/Login.java index 4f3c92a..73e0ed9 100644 --- a/src/Login.java +++ b/src/Login.java @@ -21,16 +21,6 @@ public class Login { while (true) { - while(password.isEmpty() || phoneNumber.isEmpty()) - { - System.out.println("Login fehlgeschlagen. Eingabe ist leer, versuchen Sie es erneut."); - System.out.println(""); - System.out.print("Telefonnummer: "); - phoneNumber = leser.nextLine(); - System.out.print("Passwort: "); - password = leser.nextLine(); - } - boolean error = false; error = isError(error, phoneNumber); From 58ec030102281ac4160d814c0ee4bfce18da2a70 Mon Sep 17 00:00:00 2001 From: Felix Woestemeyer Date: Tue, 17 Jan 2023 16:37:39 +0100 Subject: [PATCH 6/8] =?UTF-8?q?Korrektur=20der=20Syntax=20und=20einhaltlic?= =?UTF-8?q?he=20toString=20f=C3=BCr=20das=20Speichern=20der=20Daten.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Data.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Data.java b/src/Data.java index b846832..da95754 100644 --- a/src/Data.java +++ b/src/Data.java @@ -211,6 +211,16 @@ public class Data { for (String zeile : listToWrite) { new FileWriter(pathWrite).write(zeile); } + }else + { + Scanner scanner = new Scanner(System.in); + System.out.println("Der Pfad oder die Datei "+ pathWrite +" existiert nicht!\nMöchten Sie unter dem Pfad "+ pathWrite+ " eine neue Datei erstellen? (Y/N)"); + if(scanner.nextLine().equals("Y")){ + new File(pathWrite).createNewFile(); + System.out.println("Die Datei "+ pathWrite+" wurde erfolgreich erstellt"); + }else if(!scanner.nextLine().equals("N") && !scanner.nextLine().equals("Y")){ + System.out.println("Es ist ein Fehler mit ihrer Antwort aufgetreten."); + } } }catch(IOException e){ e.printStackTrace(); From 9663777e253ad95a262e71b7666d64cb8c58f03d Mon Sep 17 00:00:00 2001 From: Felix Woestemeyer Date: Tue, 17 Jan 2023 16:43:28 +0100 Subject: [PATCH 7/8] Korrektur der writeData. --- src/Data.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Data.java b/src/Data.java index da95754..a420556 100644 --- a/src/Data.java +++ b/src/Data.java @@ -219,7 +219,7 @@ public class Data { new File(pathWrite).createNewFile(); System.out.println("Die Datei "+ pathWrite+" wurde erfolgreich erstellt"); }else if(!scanner.nextLine().equals("N") && !scanner.nextLine().equals("Y")){ - System.out.println("Es ist ein Fehler mit ihrer Antwort aufgetreten."); + System.out.println("Es ist ein Fehler mit ihrer Antwort aufgetreten!"); } } }catch(IOException e){ From f35554f858048bd5ed03065b9866bdabd04e8731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=BCsterhaus?= Date: Tue, 17 Jan 2023 17:03:44 +0100 Subject: [PATCH 8/8] =?UTF-8?q?changeOrder=20methode=20erg=C3=A4nzt=20+=20?= =?UTF-8?q?test=20order=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- orders.txt | 12 ++++++ orders2.txt | 12 ++++++ out/production/VPR_SCRIPT/Data.class | Bin 4864 -> 8885 bytes out/production/VPR_SCRIPT/Execute.class | Bin 2309 -> 3033 bytes src/Data.java | 50 ++++++++++++++++++++++++ src/Execute.java | 28 ++++++++++++- 6 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 orders.txt create mode 100644 orders2.txt diff --git a/orders.txt b/orders.txt new file mode 100644 index 0000000..14abfb1 --- /dev/null +++ b/orders.txt @@ -0,0 +1,12 @@ +12.12.2022;1234567;Vegan;Dessert V +12.12.2022;7654321;Vegan;Dessert V +12.12.2022;123;Vegetarisch;Dessert V +12.12.2022;9999999;Fleisch;Dessert +12.12.2022;1234567;Vegan;Dessert V +12.12.2022;7654321;Vegan;Dessert V +12.12.2022;123;Vegetarisch;Dessert V +12.12.2022;9999999;Fleisch;Dessert +12.12.2022;1234567;Vegan;Dessert V +12.12.2022;7654321;Vegan;Dessert V +12.12.2022;123;Vegetarisch;Dessert V +12.12.2022;1234;Fleisch;Dessert \ No newline at end of file diff --git a/orders2.txt b/orders2.txt new file mode 100644 index 0000000..d669447 --- /dev/null +++ b/orders2.txt @@ -0,0 +1,12 @@ +12.12.2022;1234567;Vegan;Dessert V +12.12.2022;7654321;Vegan;Dessert V +12.12.2022;123;Vegetarisch;Dessert V +12.12.2022;9999999;Fleisch;Dessert +12.12.2022;1234567;Vegan;Dessert V +12.12.2022;7654321;Vegan;Dessert V +12.12.2022;123;Vegetarisch;Dessert V +12.12.2022;9999999;Fleisch;Dessert +12.12.2022;1234567;Vegan;Dessert V +12.12.2022;7654321;Vegan;Dessert V +12.12.2022;123;Vegetarisch;Dessert V +12.12.2022;1234;Fleisch;Dessert diff --git a/out/production/VPR_SCRIPT/Data.class b/out/production/VPR_SCRIPT/Data.class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5xz|M&lV zET?|jXx+N^{S9D*vsbKvSj}X=A~{<*pexm_gTZ28azL@^xn{#H1=_dwc-o%u{GifY zEo!^mY*gKn_P5*ph5YWEZ8EJ;1&b1%!AvJFQC4)%IES5l+3}0{Jwe6ui;B2DH1CwF zir)Tb|MgDpADPi^Fr0hA#226?3xl~%4p9+OZb=aIWJpbs`)}Sl>Ts_9bF6otNg%1a zO%BW9n=C3G8h1kO3tDo0+xMgtyQrJ1zCZ{sv#8x%< zQlg`Bz1jS($(E;nDc<+uE40ZR5UGd}7x|j}<>gdz#s;pTu0-zFMTTxjP!rj?9>5#C z8QI?AZ2^(w_N{b~1a-OouyLn$9ixzPu8|xvuX2CNZ7`LIHP}0p$Rtv_L2-o*q8$|N zG+h}p6K^m(WL>0Btksr(KJq6+h=m5(R_?;zxhouO#k-<~@hcRr)+Av`68_iSYpX4+ zkXv;3+R1xiMK8~@5my2{9+1t- zvcx0OxlJ4wfK%i+#{idjl*?@9J4wCCAV10=ZnK3uY~xoR=Qp0<4~A5NVU^-Zm19J0 zVY@1@Lph8pk1;jJxH`gwI>Ao0%F{LV4bMaao0FmR2#q5w(;kk8cQ`8CE%i0;a!khA zrOxx75NhMN%JRP0+Bu~j9V3R?Ur_*^MqBZms3)=42BhHbEAPYtBQiGv964UtslGul>5%#2dX)D+KW4# zrc)ZyY9c~dQ40y3`eWM^m47PTl%?UfC7U&FhmiDXND;= z!kY*c*{(8PcbAl-s7M<*HnCkZY_VOx{*w$lvKrxoU0vW2c#eJLY~g1);82DOOmM`p w{-jJ7C!Ff>6&cRzWH=Ma{eTAJT#O54V%RmJ24jd@e@y@CVL^*al{{Si1GRrVEC2ui diff --git a/src/Data.java b/src/Data.java index a420556..058ee5b 100644 --- a/src/Data.java +++ b/src/Data.java @@ -308,5 +308,55 @@ public class Data { } return inputValid; } + + /** + * The method changes the orders.txt file by removing canceled orders + * + * @return ArrayList\ changedOrderList + * @author Felix Düsterhaus + */ + + public ArrayList changeOrder(String userLogin) { + + /* + File orderFile = new File("C:/Unterricht/VPR/orders.txt"); + if (orderFile.delete()) { + System.out.println("Datei gelöscht: " + orderFile.getName()); + } else { + System.out.println("Fehler, " + orderFile.getName() + " nicht gelöscht."); + } + */ + + ArrayList changedOrderList = new ArrayList<>(); + List rows = getRows(); + int changedEntries = 0; + + for (String row : rows) { + String[] parts = row.split(";"); + + String date = parts[0]; + String user = parts[1]; + String mealtyp = parts[2]; + String deserttyp = parts[3]; + if(!userLogin.equals(user)) { + changedOrderList.add(new Order(date, user, mealtyp, deserttyp)); + } else { + changedEntries++; + } + } + + try { + FileWriter writer = new FileWriter("orders2.txt"); + for(Order str: changedOrderList) { + writer.write(str + System.lineSeparator()); + } + writer.close(); + System.out.println("Daten gelöscht"); + System.out.println(changedEntries + " Einträge entfernt."); + } catch (IOException e) { + e.printStackTrace(); + } + return changedOrderList; + } } diff --git a/src/Execute.java b/src/Execute.java index 1d4415a..eb105e8 100644 --- a/src/Execute.java +++ b/src/Execute.java @@ -1,3 +1,5 @@ +import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Scanner; @@ -5,7 +7,7 @@ import java.util.Scanner; * The class Execute is the execution file for the whole program. */ public class Execute { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { //EXECUTE MENU OVERVIEW Data data = new Data("menue.txt"); ArrayList menu = data.readMenu(); @@ -45,5 +47,29 @@ public class Execute { String password = leser.nextLine(); login.toLogin(userData.readUser(), password, phoneNumber); + + /** + * Test zum Daten löschen + * @author Felix Düsterhaus + */ + Data orderData = new Data("orders2.txt"); + System.out.print("Möchten Sie Einträge löschen? (Y/N) "); + String orderChangeDecision = leser.nextLine(); + if (orderChangeDecision.equals("Y") || orderChangeDecision.equals("y")) { + ArrayList changedOrderList = orderData.changeOrder(phoneNumber); + } else if (orderChangeDecision.equals("N") || orderChangeDecision.equals("n")) { + System.out.println("Daten werden nicht geändert."); + } + while(!(orderChangeDecision.equals("Y") || orderChangeDecision.equals("y") || orderChangeDecision.equals("N") || orderChangeDecision.equals("n"))) { + System.out.println("Bitte eine gültige Aussage treffen.\n"); + System.out.print("Möchten Sie Einträge löschen? (Y/N) "); + orderChangeDecision = leser.nextLine(); + + if (orderChangeDecision.equals("Y") || orderChangeDecision.equals("y")) { + ArrayList changedOrderList = orderData.changeOrder(phoneNumber); + } else if (orderChangeDecision.equals("N") || orderChangeDecision.equals("n")) { + System.out.println("Daten werden nicht geändert."); + } + } } }