Tagname aus Datum erzeugt
This commit is contained in:
parent
bf8cf182db
commit
27b2186c87
Binary file not shown.
@ -4,120 +4,169 @@ 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.time.DayOfWeek;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**GeneralMethods is a class for commen public methods.
|
/**
|
||||||
*
|
* GeneralMethods is a class for commen public methods.
|
||||||
* @auhtor Felix Wöstemeyer
|
|
||||||
*
|
*
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
|
* @auhtor Felix Wöstemeyer
|
||||||
*/
|
*/
|
||||||
public class GeneralMethods {
|
public class GeneralMethods {
|
||||||
/**The method writeData saves the given data to a certain file.
|
|
||||||
*
|
/**
|
||||||
* @param pathWrite the given filepath to write
|
* The method getDayNumberNew() gets the Number of day in week
|
||||||
* @param data the data to be saved
|
* @param dateString date as String e.g. 12.12.2022
|
||||||
|
* @return the Number of day in week
|
||||||
|
* @version 1.0
|
||||||
|
* @author Madeleine Vigier
|
||||||
*/
|
*/
|
||||||
public static void writeData(String pathWrite, ArrayList<String> data){
|
public static String getDayNumberNew(String dateString) {
|
||||||
try{
|
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(pathWrite));
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||||
for (String d : data) {
|
formatter = formatter.withLocale(Locale.GERMANY); // Locale specifies human language for translating, and cultural norms for lowercase/uppercase and abbreviations and such. Example: Locale.US or Locale.CANADA_FRENCH
|
||||||
writer.write(d);
|
LocalDate date = LocalDate.parse(dateString, formatter);
|
||||||
writer.newLine();
|
|
||||||
}
|
DayOfWeek day = date.getDayOfWeek();
|
||||||
writer.close();
|
return getDayName(day.getValue());
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Author: Sabine Gubitz
|
* The method getDayName() gets the weekday
|
||||||
*ddd
|
* @param dayNumber dayNumber e.g. 1 for Monday
|
||||||
* The method read Data interprets a file and returns an useable list for other methods.
|
* @return weekday
|
||||||
* Files to be read have to use : as a divider between attributes
|
* @version 1.0
|
||||||
*
|
* @author Madeleine Vigier
|
||||||
* @param pathRead determines the filename of the file that will be read
|
|
||||||
* @return menueList, userList, orderList depending on Data read
|
|
||||||
*/
|
*/
|
||||||
public static ArrayList<String> readData(String pathRead) {
|
public static String getDayName(int dayNumber) {
|
||||||
Path path = Paths.get(pathRead);
|
if (dayNumber == 1) {
|
||||||
|
return "Montag";
|
||||||
try {
|
|
||||||
List<String> rows = Files.readAllLines(path);
|
|
||||||
|
|
||||||
if (pathRead.equals("menue.txt")) {
|
|
||||||
ArrayList<String> menueList = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String row : rows) {
|
|
||||||
String[] parts = row.split(":");
|
|
||||||
|
|
||||||
String day = parts[0];
|
|
||||||
String date = parts[1];
|
|
||||||
String meat = parts[2];
|
|
||||||
String vegi = parts[3];
|
|
||||||
String vegan = parts[4];
|
|
||||||
String desert1 = parts[5];
|
|
||||||
String desert2 = parts[6];
|
|
||||||
menueList.add(day + "," + date + "," + meat + "," + vegi + "," + vegan + "," + desert1 + "," + desert2);
|
|
||||||
}
|
}
|
||||||
return menueList;
|
if (dayNumber == 2) {
|
||||||
|
return "Dienstag";
|
||||||
} else if (pathRead.equals("users.txt")){
|
|
||||||
ArrayList<String> 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];
|
|
||||||
}
|
}
|
||||||
return userList;
|
if (dayNumber == 3) {
|
||||||
|
return "Mittwoch";
|
||||||
} else if (pathRead.equals("orders.txt")) {
|
}
|
||||||
ArrayList<String> orderList = new ArrayList<>();
|
if (dayNumber == 4) {
|
||||||
|
return "Donnerstag";
|
||||||
for (String row : rows) {
|
}
|
||||||
String[] parts = row.split(":");
|
if (dayNumber == 5) {
|
||||||
|
return "Freitag";
|
||||||
String date = parts[0];
|
|
||||||
String meat = parts[1];
|
|
||||||
String meatCount = parts[2];
|
|
||||||
String vegi = parts[3];
|
|
||||||
String vegiCount = parts[4];
|
|
||||||
String vegan = parts[5];
|
|
||||||
String veganCount = parts[6];
|
|
||||||
String desert1 = parts[7];
|
|
||||||
String desert1Count = parts[8];
|
|
||||||
String desert2 = parts[9];
|
|
||||||
String desert2Count = parts[10];
|
|
||||||
}
|
}
|
||||||
return orderList;
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// /**The method writeData saves the given data to a certain file.
|
||||||
/**
|
// *
|
||||||
* The method writeData2 writes the data of a List into a txt file.
|
// * @param pathWrite the given filepath to write
|
||||||
* @param pathWrite determines the filename of the file that will be written
|
// * @param data the data to be saved
|
||||||
* @param listToWrite determines which ArrayList is to be used for writing the file
|
// */
|
||||||
*/
|
// public static void writeData(String pathWrite, ArrayList<String> data){
|
||||||
public void writeData2 (String pathWrite, ArrayList<String> listToWrite){
|
// try{
|
||||||
if (pathWrite.equals("users.txt")) {
|
// BufferedWriter writer = new BufferedWriter(new FileWriter(pathWrite));
|
||||||
|
// for (String d : data) {
|
||||||
} else if (pathWrite.equals("orders.txt")) {
|
// writer.write(d);
|
||||||
|
// writer.newLine();
|
||||||
}
|
// }
|
||||||
}
|
// writer.close();
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * Author: Sabine Gubitz
|
||||||
|
// *ddd
|
||||||
|
// * The method read Data interprets a file and returns an useable list for other methods.
|
||||||
|
// * Files to be read have to use : as a divider between attributes
|
||||||
|
// *
|
||||||
|
// * @param pathRead determines the filename of the file that will be read
|
||||||
|
// * @return menueList, userList, orderList depending on Data read
|
||||||
|
// */
|
||||||
|
// public static ArrayList<String> readData(String pathRead) {
|
||||||
|
// Path path = Paths.get(pathRead);
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
// List<String> rows = Files.readAllLines(path);
|
||||||
|
//
|
||||||
|
// if (pathRead.equals("menue.txt")) {
|
||||||
|
// ArrayList<String> menueList = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// for (String row : rows) {
|
||||||
|
// String[] parts = row.split(":");
|
||||||
|
//
|
||||||
|
// String day = parts[0];
|
||||||
|
// String date = parts[1];
|
||||||
|
// String meat = parts[2];
|
||||||
|
// String vegi = parts[3];
|
||||||
|
// String vegan = parts[4];
|
||||||
|
// String desert1 = parts[5];
|
||||||
|
// String desert2 = parts[6];
|
||||||
|
// menueList.add(day + "," + date + "," + meat + "," + vegi + "," + vegan + "," + desert1 + "," + desert2);
|
||||||
|
// }
|
||||||
|
// return menueList;
|
||||||
|
//
|
||||||
|
// } else if (pathRead.equals("users.txt")){
|
||||||
|
// ArrayList<String> 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];
|
||||||
|
// }
|
||||||
|
// return userList;
|
||||||
|
//
|
||||||
|
// } else if (pathRead.equals("orders.txt")) {
|
||||||
|
// ArrayList<String> orderList = new ArrayList<>();
|
||||||
|
//
|
||||||
|
// for (String row : rows) {
|
||||||
|
// String[] parts = row.split(":");
|
||||||
|
//
|
||||||
|
// String date = parts[0];
|
||||||
|
// String meat = parts[1];
|
||||||
|
// String meatCount = parts[2];
|
||||||
|
// String vegi = parts[3];
|
||||||
|
// String vegiCount = parts[4];
|
||||||
|
// String vegan = parts[5];
|
||||||
|
// String veganCount = parts[6];
|
||||||
|
// String desert1 = parts[7];
|
||||||
|
// String desert1Count = parts[8];
|
||||||
|
// String desert2 = parts[9];
|
||||||
|
// String desert2Count = parts[10];
|
||||||
|
// }
|
||||||
|
// return orderList;
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * The method writeData2 writes the data of a List into a txt file.
|
||||||
|
// * @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 writeData2 (String pathWrite, ArrayList<String> listToWrite){
|
||||||
|
// if (pathWrite.equals("users.txt")) {
|
||||||
|
//
|
||||||
|
// } else if (pathWrite.equals("orders.txt")) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user