Merge remote-tracking branch 'origin/master'
# Conflicts: # out/production/VPR_SCRIPT/Data.class # out/production/VPR_SCRIPT/Execute.class
This commit is contained in:
commit
6ffc7a6868
12
orders.txt
Normal file
12
orders.txt
Normal 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
12
orders2.txt
Normal 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.
151
src/Data.java
151
src/Data.java
@ -1,10 +1,14 @@
|
|||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.sql.Array;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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.
|
* Data is a class to edit files.
|
||||||
@ -185,9 +189,9 @@ public class Data {
|
|||||||
|
|
||||||
String date = parts[0];
|
String date = parts[0];
|
||||||
String user = parts[1];
|
String user = parts[1];
|
||||||
String mealtyp = parts[3];
|
String mealtype = parts[3];
|
||||||
String deserttyp = parts[5];
|
String deserttype = parts[5];
|
||||||
orderList.add(new Order(date, user, mealtyp, deserttyp));
|
orderList.add(new Order(date, user, mealtype, deserttype));
|
||||||
}
|
}
|
||||||
return null;//orderList
|
return null;//orderList
|
||||||
|
|
||||||
@ -196,14 +200,30 @@ public class Data {
|
|||||||
/**
|
/**
|
||||||
* The method writeData writes the data of a List into a txt file.
|
* 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 pathWrite determines the filename of the file that will be written
|
||||||
* @param listToWrite determines which ArrayList is to be used for writing the file
|
* @param listToWrite determines which ArrayList is to be used for writing the file
|
||||||
*/
|
*/
|
||||||
public void writeData(String pathWrite, ArrayList<String> listToWrite) {
|
public void writeData(String pathWrite, ArrayList<String> listToWrite) {
|
||||||
if (pathWrite.equals("users.txt")) {
|
try {
|
||||||
|
if (new File(pathWrite).exists()) {
|
||||||
} else if (pathWrite.equals("orders.txt")) {
|
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
@ -5,7 +7,7 @@ import java.util.Scanner;
|
|||||||
* The class Execute is the execution file for the whole program.
|
* The class Execute is the execution file for the whole program.
|
||||||
*/
|
*/
|
||||||
public class Execute {
|
public class Execute {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws IOException {
|
||||||
//EXECUTE MENU OVERVIEW
|
//EXECUTE MENU OVERVIEW
|
||||||
Data data = new Data("menue.txt");
|
Data data = new Data("menue.txt");
|
||||||
ArrayList<Menu> menu = data.readMenu();
|
ArrayList<Menu> menu = data.readMenu();
|
||||||
@ -45,5 +47,29 @@ public class Execute {
|
|||||||
String password = leser.nextLine();
|
String password = leser.nextLine();
|
||||||
|
|
||||||
login.toLogin(userData.readUser(), password, phoneNumber);
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,16 +21,6 @@ public class Login {
|
|||||||
|
|
||||||
while (true) {
|
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;
|
boolean error = false;
|
||||||
error = isError(error, phoneNumber);
|
error = isError(error, phoneNumber);
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ public class Menu {
|
|||||||
String date;
|
String date;
|
||||||
String dish;
|
String dish;
|
||||||
String sideDish;
|
String sideDish;
|
||||||
String typ;
|
String type;
|
||||||
List<String> ingredients;
|
List<String> ingredients;
|
||||||
|
|
||||||
|
|
||||||
@ -20,14 +20,14 @@ public class Menu {
|
|||||||
* @param date date of meal
|
* @param date date of meal
|
||||||
* @param dish meal
|
* @param dish meal
|
||||||
* @param sideDish side dish
|
* @param sideDish side dish
|
||||||
* @param typ vegan, vegetarian or meat
|
* @param type vegan, vegetarian or meat
|
||||||
* @param ingredients list of ingredients
|
* @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.date = date;
|
||||||
this.dish = dish;
|
this.dish = dish;
|
||||||
this.sideDish = sideDish;
|
this.sideDish = sideDish;
|
||||||
this.typ = typ;
|
this.type = type;
|
||||||
this.ingredients = ingredients;
|
this.ingredients = ingredients;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,26 +47,25 @@ public class Menu {
|
|||||||
* @return typ e.g. Vegan
|
* @return typ e.g. Vegan
|
||||||
* @author Madeleine Vigier
|
* @author Madeleine Vigier
|
||||||
*/
|
*/
|
||||||
public String getTyp() {
|
public String getType() {
|
||||||
if (typ.contains("DessertV") || typ.contains("Dessert")) {
|
if (type.contains("DessertV") || type.contains("Dessert")) {
|
||||||
return "";
|
return "";
|
||||||
} else {
|
} 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
|
* @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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return dish + "\n" + sideDish
|
return date+";"+dish+";"+sideDish+";"+type+";"+ingredients;
|
||||||
+ "\n" + ingredients.toString().replace("[", "").replace("]", "") + "\n" + getTyp() + "\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,15 +8,20 @@
|
|||||||
public class Order {
|
public class Order {
|
||||||
String date; //date for the meal, not the day it was ordered
|
String date; //date for the meal, not the day it was ordered
|
||||||
String user; //phone number of the user account
|
String user; //phone number of the user account
|
||||||
String mealtyp; //meat, vegi or vegan
|
String mealtype; //meat, vegi or vegan
|
||||||
String deserttyp; //desert or vegan desert
|
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.date = date;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.mealtyp = mealtyp;
|
this.mealtype = mealtype;
|
||||||
this.deserttyp = deserttyp;
|
this.desserttype = desserttype;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return date+";"+user+";"+mealtype+";"+desserttype;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
|
@ -19,7 +19,7 @@ public class User {
|
|||||||
* @param nameParent2 name of the second 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 billAddress the address the bill should be sent to
|
||||||
* @param phoneNumber phonenumber of one of the parents and also the username
|
* @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
|
* @param password password of the user
|
||||||
* @author Madeleine Vigier
|
* @author Madeleine Vigier
|
||||||
*/
|
*/
|
||||||
@ -80,13 +80,6 @@ public class User {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "User{" +
|
return nameParent1 + ";" + nameParent2 + ";" + billAddress + ";" + phoneNumber + ";" + nameChildren + ";" + password;
|
||||||
"nameParent1='" + nameParent1 + '\'' +
|
|
||||||
", nameParent2='" + nameParent2 + '\'' +
|
|
||||||
", billAddress='" + billAddress + '\'' +
|
|
||||||
", phonenumber='" + phoneNumber + '\'' +
|
|
||||||
", nameChildren='" + nameChildren + '\'' +
|
|
||||||
", password='" + password + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user