diff --git a/src/main/java/com/example/vpr_javafx/Data.java b/src/main/java/com/example/vpr_javafx/Data.java new file mode 100644 index 0000000..5b3dc5b --- /dev/null +++ b/src/main/java/com/example/vpr_javafx/Data.java @@ -0,0 +1,364 @@ +package com.example.vpr_javafx; + +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.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. + * + * @author Madeleine Vigier + * @version 1.3 + */ +public class Data { + private String pathRead; + + public Data(String pathRead) { + this.pathRead = pathRead; + } + + /** + * readUser() is a method to split user.txt into lines and save them in an arraylist + * + * @return Arraylist userList + * @author Madeleine Vigier, Sabine Gubitz + */ + public ArrayList readUser() { + List rows = getRows(); + ArrayList userList = new ArrayList<>(); + + for (String row : rows) { + String[] parts = row.split(";"); + + String nameParent1 = parts[0]; + String nameParent2 = parts[1]; + String billAddress = parts[2]; + String phonenumber = parts[3]; + String nameChildren = parts[4]; + String password = parts[5]; + userList.add(new com.example.vpr_javafx.User(nameParent1, nameParent2, billAddress, phonenumber, nameChildren, password)); + } + return userList; + + } + + + /** + * readMenue() is a method to split menue.txt into lines and save them in an arraylist + * + * @return Arraylist menuelist + * @author Madeleine Vigier, Sabine Gubitz + */ + public ArrayList readMenu() { + + List rows = getRows(); + ArrayList menuList = new ArrayList<>(); + + + for (String row : rows) { + + String[] parts = row.split(";"); + + + String date = parts[0]; + String dish = parts[1]; + String sideDish = parts[2]; + String typ = parts[3]; + String ingredient = parts[4]; + + List ingredients = new ArrayList<>(); + + if (!ingredient.isEmpty()) { + ingredients.add("a"); //eggs + } + + ingredient = parts[5]; + if (!ingredient.isEmpty()) { + ingredients.add("d"); //peanuts + } + ingredient = parts[6]; + if (!ingredient.isEmpty()) { + ingredients.add("m"); //fish + } + ingredient = parts[7]; + if (!ingredient.isEmpty()) { + ingredients.add("g"); //grains + } + ingredient = parts[8]; + if (!ingredient.isEmpty()) { + ingredients.add("f"); //crustaceans + } + ingredient = parts[9]; + if (!ingredient.isEmpty()) { + ingredients.add("n"); //lupines + } + ingredient = parts[10]; + if (!ingredient.isEmpty()) { + ingredients.add("c"); //milk + } + ingredient = parts[11]; + if (!ingredient.isEmpty()) { + ingredients.add("k"); //nuts + } + ingredient = parts[12]; + if (!ingredient.isEmpty()) { + ingredients.add("j"); //sulfurDioxideAndSulfite + } + ingredient = parts[13]; + + if (!ingredient.isEmpty()) { + ingredients.add("l"); //celeriac + } + ingredient = parts[14]; + if (!ingredient.isEmpty()) { + ingredients.add("h"); //mustards + } + ingredient = parts[15]; + if (!ingredient.isEmpty()) { + ingredients.add("i"); //sesame + } + ingredient = parts[16]; + if (!ingredient.isEmpty()) { + ingredients.add("b");//soy + } + ingredient = parts[17]; + if (!ingredient.isEmpty()) { + ingredients.add("e");//molluscs + } + ingredient = parts[18]; + if (!ingredient.isEmpty()) { + ingredients.add("4"); //antioxidant + } + ingredient = parts[19]; + if (!ingredient.isEmpty()) { + ingredients.add("5"); + } + ingredient = parts[20]; + if (!ingredient.isEmpty()) { + ingredients.add("6"); //flavourEnhancer + } + ingredient = parts[21]; + if (!ingredient.isEmpty()) { + ingredients.add("8"); // preservatives + } + ingredient = parts[22]; + + if (!ingredient.isEmpty()) { + ingredients.add("3"); //nitrate + } + ingredient = parts[23]; + if (!ingredient.isEmpty()) { + ingredients.add("1");//picklingSalt + } + ingredient = parts[24]; + if (!ingredient.isEmpty()) { + ingredients.add("7"); //artificialSweetener + } + ingredient = parts[25]; + if (!ingredient.isEmpty()) { + ingredients.add("2"); //phosphate + + } + String end = parts[26]; //endpoint + + menuList.add(new com.example.vpr_javafx.Menu(date, dish, sideDish, typ, ingredients)); + } + return menuList; + } + + + /** + * readOrder() is a method to split order.txt into lines and save them in an arraylist + * + * @return Arraylist orderlist + * @author Madeleine Vigier, Sabine Gubitz + */ + public ArrayList readOrder() { + + ArrayList orderList = new ArrayList<>(); + List rows = getRows(); + + for (String row : rows) { + String[] parts = row.split(";"); + + String date = parts[0]; + String user = parts[1]; + String mealtype = parts[3]; + String deserttype = parts[5]; + orderList.add(new com.example.vpr_javafx.Order(date, user, mealtype, deserttype)); + } + return null;//orderList + + } + + /** + * 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) { + try { + if (new File(pathWrite).exists()) { + 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(); + } + } + + /** + * The method gets the rows by reading all lines of the path + * + * @return ArrayList rows + * @author Madeleine Vigier + */ + private List getRows() { + Path path = Paths.get(pathRead); + List rows = new ArrayList<>(); + try { + rows = Files.readAllLines(path); + } catch (IOException e) { + e.printStackTrace(); + } + 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-z])(?=.*\\d)[A-Za-z\\d]{8,}$"); + + 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; + } + + /** + * 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 com.example.vpr_javafx.Order(date, user, mealtyp, deserttyp)); + } else { + changedEntries++; + } + } + + try { + FileWriter writer = new FileWriter("orders2.txt"); + for(com.example.vpr_javafx.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/main/java/com/example/vpr_javafx/LoginDatei.java b/src/main/java/com/example/vpr_javafx/LoginDatei.java new file mode 100644 index 0000000..50ca177 --- /dev/null +++ b/src/main/java/com/example/vpr_javafx/LoginDatei.java @@ -0,0 +1,42 @@ +package com.example.vpr_javafx; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.List; + +public class LoginDatei +{ + private final String dateiname; + + public LoginDatei(String dateiname) + { + this.dateiname = dateiname; + } + + public HashMap readFile() + { + try { + List lines = Files.readAllLines(Paths.get(dateiname)); + + HashMap user = new HashMap<>(); + + for (int i = 0; i < lines.size(); i++) + { + String[] parts = lines.get(i).split(";"); + + String phoneNumber = parts[3]; + String password = parts[5]; + + user.put(phoneNumber, password); + } + + return user; + + } catch (IOException e) { + e.printStackTrace(); + return new HashMap<>(); + } + } +} diff --git a/src/main/java/com/example/vpr_javafx/Menu.java b/src/main/java/com/example/vpr_javafx/Menu.java new file mode 100644 index 0000000..5fe5db1 --- /dev/null +++ b/src/main/java/com/example/vpr_javafx/Menu.java @@ -0,0 +1,73 @@ +package com.example.vpr_javafx; + +import java.util.List; + +/** + * Menu is a class to built a menu + * + * @author Madeleine Vigier + * @version 1.1 + */ +public class Menu { + String date; + String dish; + String sideDish; + String type; + List ingredients; + + + /** + * constructor + * + * @param date date of meal + * @param dish meal + * @param sideDish side dish + * @param type vegan, vegetarian or meat + * @param ingredients list of ingredients + */ + public Menu(String date, String dish, String sideDish, String type, List ingredients) { + this.date = date; + this.dish = dish; + this.sideDish = sideDish; + this.type = type; + this.ingredients = ingredients; + } + + /** + * The method get Date() gets the date + * + * @return date + * @author Madeleine Vigier + */ + public String getDate() { + return date; + } + + /** + * The method getTyp() gets the typ of the meal + * + * @return typ e.g. Vegan + * @author Madeleine Vigier + */ + public String getType() { + if (type.contains("DessertV") || type.contains("Dessert")) { + return ""; + } else { + + return type; + } + } + + + /** + * 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, Felix Wöstemeyer + */ + @Override + public String toString() { + return date+";"+dish+";"+sideDish+";"+type+";"+ingredients; + } +} + diff --git a/src/main/java/com/example/vpr_javafx/Order.java b/src/main/java/com/example/vpr_javafx/Order.java new file mode 100644 index 0000000..1775a2e --- /dev/null +++ b/src/main/java/com/example/vpr_javafx/Order.java @@ -0,0 +1,28 @@ +package com.example.vpr_javafx; + +/** + * The class Order is an object class that holds the constructor for order objects. + * + * @author Sabine Gubitz + * @version 1.2 + */ + +public class Order { + String date; //date for the meal, not the day it was ordered + String user; //phone number of the user account + String mealtype; //meat, vegi or vegan + String desserttype; //desert or vegan desert + + Order(String date, String user, String mealtype, String desserttype) + { + this.date = date; + this.user = user; + this.mealtype = mealtype; + this.desserttype = desserttype; + } + + @Override + public String toString(){ + return date+";"+user+";"+mealtype+";"+desserttype; + } +} diff --git a/src/main/java/com/example/vpr_javafx/User.java b/src/main/java/com/example/vpr_javafx/User.java new file mode 100644 index 0000000..50da10a --- /dev/null +++ b/src/main/java/com/example/vpr_javafx/User.java @@ -0,0 +1,87 @@ +package com.example.vpr_javafx; + +/** + * User class creates User Objects + * + * @author Madeleine Vigier + * @version 1.2 + */ +public class User { + private String nameParent1; + private String nameParent2; + private String billAddress; + private String phoneNumber; + private String nameChildren; + private String password; + + /** + * constructor + * + * @param nameParent1 name of the first parent of the child + * @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 children + * @param password password of the user + * @author Madeleine Vigier + */ + public User(String nameParent1, String nameParent2, String billAddress, String phoneNumber, String nameChildren, String password) { + this.nameParent1 = nameParent1; + this.nameParent2 = nameParent2; + this.billAddress = billAddress; + this.phoneNumber = phoneNumber; + this.nameChildren = nameChildren; + this.password = password; + } + + /** + * the method getPhonenumber() gets the Phonenumber + * + * @return Phonenumber + * @author Madeleine Vigier + */ + public String getPhonenumber() { + return phoneNumber; + } + + /** + * the method getPassword() gets the password + * + * @return password + * @author Madeleine Vigier + */ + public String getPassword() { + return password; + } + + /** + * the method getNameParent1() gets nameParent1 + * + * @return nameParent1 + * @author Madeleine Vigier + */ + public String getNameParent1() { + return nameParent1; + } + + /** + * the method getNameParent2() gets nameParent2 + * + * @return nameParent2 + * @author Madeleine Vigier + */ + public String getNameParent2() { + return nameParent2; + } + + /** + * the methode toString() returns a String representation of an object + * + * @return a String with nameParent1, nameparent2, billAdress, phonenumber, nameChildren, password + * @author Madeleine Vigier + */ + @Override + public String toString() { + return nameParent1 + ";" + nameParent2 + ";" + billAddress + ";" + phoneNumber + ";" + nameChildren + ";" + password; + } +}