Merge remote-tracking branch 'origin/master'

# Conflicts:
#	out/production/VPR_SCRIPT/Data.class
#	out/production/VPR_SCRIPT/Execute.class
This commit is contained in:
Madeleine Vigier 2023-02-01 12:42:23 +01:00
commit 6ffc7a6868
9 changed files with 216 additions and 44 deletions

12
orders.txt Normal file
View File

@ -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

12
orders2.txt Normal file
View File

@ -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

Binary file not shown.

View File

@ -1,10 +1,14 @@
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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Data is a class to edit files.
@ -185,9 +189,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
@ -196,14 +200,30 @@ 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<String> listToWrite) {
if (pathWrite.equals("users.txt")) {
} else if (pathWrite.equals("orders.txt")) {
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();
}
}
@ -223,5 +243,120 @@ 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-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\<Order> changedOrderList
* @author Felix Düsterhaus
*/
public ArrayList<Order> 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<Order> changedOrderList = new ArrayList<>();
List<String> 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;
}
}

View File

@ -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> 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<Order> 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<Order> changedOrderList = orderData.changeOrder(phoneNumber);
} else if (orderChangeDecision.equals("N") || orderChangeDecision.equals("n")) {
System.out.println("Daten werden nicht geändert.");
}
}
}
}

View File

@ -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);

View File

@ -10,7 +10,7 @@ public class Menu {
String date;
String dish;
String sideDish;
String typ;
String type;
List<String> 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<String> ingredients) {
public Menu(String date, String dish, String sideDish, String type, List<String> 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;
}
}

View File

@ -8,15 +8,20 @@
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;
}
// @Override

View File

@ -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;
}
}