From 6e583b939f929528d8082f2a8ba1c65c0a3402bd Mon Sep 17 00:00:00 2001 From: pbd2h21avi Date: Wed, 14 Dec 2022 20:38:33 +0100 Subject: [PATCH] Methoden angelegt/angepasst --- src/Data.java | 336 ++++++++++++++++++++++++++++---------------------- 1 file changed, 187 insertions(+), 149 deletions(-) diff --git a/src/Data.java b/src/Data.java index 74d65a1..aad4509 100644 --- a/src/Data.java +++ b/src/Data.java @@ -8,7 +8,7 @@ import java.util.List; /** * Data is a class to edit files. * @author Madeleine Vigier - * @version 1.1 + * @version 1.3 */ public class Data { private String pathRead; @@ -16,157 +16,184 @@ public class Data { 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 + * @version 1.3 + */ + 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 User(nameParent1,nameParent2,billAddress,phonenumber,nameChildren,password)); + } + return userList; + + } + /** - * readData() is a method to split a file into lines and save them in an arraylist - * @return Arraylist 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 - * @version 1.1 + * @version 1.3 */ - public ArrayList readData() { - Path path = Paths.get(pathRead); + public ArrayList readMenue(){ + ArrayList menueList = new ArrayList<>(); + List rows = getRows(); - try { - List rows = Files.readAllLines(path); -//Object class Meal is still missing and needs to be added - if (pathRead.equals("menue.csv")) { - ArrayList menueList = new ArrayList<>(); + for (String row : rows) { + String[] parts = row.split(";"); - //Booleans for allergens - boolean eggs = false, peanuts = false, fish = false, grains = false, crustaceans = false, - lupines = false, milk = false, nuts = false, sulfurDioxideAndSulfite = false, celeriac = false, - mustards = false, sesame = false, soy = false, molluscs = false; + String date = parts[1]; + String dish = parts[2]; + String sideDish = parts[3]; + String typ = parts[4]; + String desertV = parts[5]; + String desert = parts[6]; + String allergens = parts[7]; - //Booleans for additives - boolean antioxidant = false, artificialColours = false, flavourEnhancer = false, preservatives = false, - nitrate = false, picklingSalt = false, phosphate = false, artificialSweetener = false; + + boolean eggs = false; + if (allergens != "") { + eggs = true; + } + allergens = parts[8]; + boolean peanuts = false; + if (allergens != "") { + peanuts = true; + } + allergens = parts[9]; + boolean fish = false; + if (allergens != "") { + fish = true; + } + allergens = parts[10]; + boolean grains = false; + if (allergens != "") { + grains = true; + } + allergens = parts[11]; + boolean crustaceans = false; + if (allergens != "") { + crustaceans = true; + } + allergens = parts[12]; + boolean lupines = false; + if (allergens != "") { + lupines = true; + } + allergens = parts[13]; + boolean milk = false; + if (allergens != "") { + milk = true; + } + allergens = parts[14]; + boolean nuts = false; + if (allergens != "") { + nuts = true; + } + allergens = parts[15]; + boolean sulfurDioxideAndSulfite = false; + if (allergens != "") { + sulfurDioxideAndSulfite = true; + } + allergens = parts[16]; + boolean celeriac = false; + if (allergens != "") { + celeriac = true; + } + allergens = parts[17]; + boolean mustards = false; + if (allergens != "") { + mustards = true; + } + allergens = parts[18]; + boolean sesame = false; + if (allergens != "") { + sesame = true; + } + allergens = parts[19]; + boolean soy = false; + if (allergens != "") { + soy = true; + } + allergens = parts[20]; + boolean molluscs = false; + if (allergens != "") { + molluscs = true; + } + String additives = parts[21]; + boolean antioxidant = false; + if (additives != "") { + antioxidant = true; + } + additives = parts[22]; + boolean artificialColours = false; + if (additives != "") { + artificialColours = true; + } + additives = parts[23]; + boolean flavourEnhancer = false; + if (additives != "") { + flavourEnhancer = true; + } + additives = parts[24]; + boolean preservatives = false; + if (additives != "") { + preservatives = true; + } + additives = parts[25]; + boolean nitrate = false; + if (additives != "") { + nitrate = true; + } + additives = parts[26]; + boolean picklingSalt = false; + if (additives != "") { + picklingSalt = true; + } + additives = parts[27]; + boolean phosphate = false; + if (additives != "") { + phosphate = true; + } + additives = parts[28]; + boolean artificialSweetener = false; + if (additives != "") { + artificialSweetener = true; + } + + menueList.add(new Menue(date, dish, sideDish, typ, desertV, desert, eggs, peanuts, fish, grains, + crustaceans, lupines, milk, nuts, sulfurDioxideAndSulfite, celeriac, mustards, sesame, + soy, molluscs, antioxidant, artificialColours, flavourEnhancer, preservatives, nitrate, + picklingSalt, phosphate, artificialSweetener)); + } + return menueList; + } + /** + * readOrder() is a method to split a order.txt into lines and save them in an arraylist + * @return Arraylist orderlist + * @author Madeleine Vigier, Sabine Gubitz + * @version 1.2 + */ + public ArrayList readOrder(){ + + ArrayList orderList = new ArrayList<>(); + List rows = getRows(); for (String row : rows) { - String[] parts = row.split(":"); - - String date = parts[1]; - String dish = parts[2]; - String sideDish = parts[3]; - String typ = parts[4]; - String desertV = parts[5]; - String desert = parts[6]; - String allergens = parts[7]; - if ( allergens != "") { - eggs = true; - } - allergens = parts[8]; - if ( allergens != "") { - peanuts = true; - } - allergens = parts[9]; - if ( allergens != "") { - fish = true; - } - allergens = parts[10]; - if ( allergens != "") { - grains = true; - } - allergens = parts[11]; - if ( allergens != "") { - crustaceans = true; - } - allergens = parts[12]; - if ( allergens != "") { - lupines = true; - } - allergens = parts[13]; - if ( allergens != "") { - milk = true; - } - allergens = parts[14]; - if ( allergens != "") { - nuts = true; - } - allergens = parts[15]; - if ( allergens != "") { - sulfurDioxideAndSulfite = true; - } - allergens = parts[16]; - if ( allergens != "") { - celeriac = true; - } - allergens = parts[17]; - if ( allergens != "") { - mustards = true; - } - allergens = parts[18]; - if ( allergens != "") { - sesame = true; - } - allergens = parts[19]; - if ( allergens != "") { - soy = true; - } - allergens = parts[20]; - if ( allergens != "") { - molluscs = true; - } - String additives = parts[21]; - if ( additives != "") { - antioxidant = true; - } - additives = parts[22]; - if ( additives != "") { - artificialColours = true; - } - additives = parts[23]; - if ( additives != "") { - flavourEnhancer = true; - } - additives = parts[24]; - if ( additives != "") { - preservatives = true; - } - additives = parts[25]; - if ( additives != "") { - nitrate = true; - } - additives = parts[26]; - if ( additives != "") { - picklingSalt = true; - } - additives = parts[27]; - if ( additives != "") { - phosphate = true; - } - additives = parts[28]; - if ( additives != "") { - artificialSweetener = true; - } - - //menueList.add(new Meal(date, dish, sideDish, typ, desertV, desert, eggs, peanuts, fish, grains, - // crustaceans, lupines, milk, nuts, sulfurDioxideAndSulfite, celeriac, mustards, sesame, - // soy, molluscs, antioxidant, artificialColours, flavourEnhancer, preservatives, nitrate, - // picklingSalt, phosphate, artificialSweetener)); - } - return null;//menueList; - - } else if (pathRead.equals("users.txt")){ - 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 User(nameParent1,nameParent2,billAddress,phonenumber,nameChildren,password)); - } - return userList; -//Object class Order is still missing and needs to be added - } else if (pathRead.equals("orders.txt")) { - ArrayList orderList = new ArrayList<>(); - - for (String row : rows) { - String[] parts = row.split(":"); + String[] parts = row.split(";"); String date = parts[0]; String meat = parts[1]; @@ -184,14 +211,8 @@ public class Data { } return null;//orderList - } - } catch (IOException e) { - e.printStackTrace(); - } - return null; } - /** * The method writeData writes the data of a List into a txt file. * @param pathWrite determines the filename of the file that will be written @@ -205,4 +226,21 @@ public class Data { } } + /** + * The method gets the rows by reading all lines of the path + * @return ArrayList rows + * @author Madeleine Vigier + * @version 1.0 + */ + private List getRows() { + Path path = Paths.get(pathRead); + List rows = new ArrayList<>(); + try { + rows = Files.readAllLines(path); + } catch (IOException e) { + e.printStackTrace(); + } + return rows; + } } +