changeOrder methode ergänzt + test order files
This commit is contained in:
parent
9663777e25
commit
f35554f858
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.
Binary file not shown.
@ -308,5 +308,55 @@ public class Data {
|
||||
}
|
||||
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.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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user