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] =?UTF-8?q?changeOrder=20methode=20erg=C3=A4nzt=20+=20test?= =?UTF-8?q?=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 index b6b12b9a856792b3201419b8310d1584846570b4..6447c1aa717dbbca03ff8b993c2df9f3c8a4ed8a 100644 GIT binary patch literal 8885 zcmb_i3w%`7ng5@gnYni+HxL2=1_TC)KoUqG%EJT@3?P9dAc62kZ)R?ifyqpqx#8h! zrMm4}+wQv72Z%2g&04KnT@9~dAK2EdwcTy0Ypbnp+iknA+Pd9tb=Bh zK62cgil%f*jRZP$^5n+K* zxp{I54-vP_v|**v0^*}BT<*L% zW2QrxgL-MDc><{-t4FT=V~tdIO8qzJxEPmEEk=xHuFOAy<0(zm+ohxnbu5zFRpXge zef`!!4VO|0hO}OTh9&IBG|-zwpN8dZdNf?lrdz{GHc1Vu*+ez0VY64mS~hz$w6aNP zXlK)_VFR1EhK+2xG;CsHYUpHhiH5Cg7HHVcW}$|iY!++S&E{eaSF@R~p^MET4HQE( zsOYAG+sx!Z2qt=^g5v@^^2KxA`2VBMoR3#`s@O|ESf7qbo9;oM+%hS!?vJ*m+@fDV zx7|CQs$U&Xm?5N)mOC->3T)>JCvBX&^=m!xqo{X$EdlP0l(igWP z@!m9hE0Wg!RN9Id1Kq^*v}u{i=_)>#CvwaBRR^MGzZFkW&`0sOj?c>!Gujru!!n|K zH>HgzUGs171r<-~cnW`;U7n=Mx+y{Z24)uOv4ndFG!>Dd2xz)u74V=FJ%b??Cv=>| zsS(>qZE+i&+Ka77B%~eqnAKS!rxAHe!xIB^_VJSLk86NJyJK z<^d@WgNLrJMpJ$L+*M$15vlU`C|KB};T#XPd-i2Z>uPqan7iGWd+n}j`)Oya+8x*# z+jZUIIX6^k_?p1-)>ID-*i8fWn3-sA!ss!Rb&*v}%|@4L8#rN_={b>oW;!zv?KP8; zj<^{yGZCKC9I)y%d_#aa{O@SHO=iOEP9>8AeSK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/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."); + } + } } }