code bereinigt, Methoden angepasst, java doc hinzugefügt

This commit is contained in:
Madeleine Vigier 2022-12-07 12:02:02 +01:00
parent 4f3522cf0e
commit b8f0ebb121
5 changed files with 164 additions and 74 deletions

106
src/Data.java Normal file
View File

@ -0,0 +1,106 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
/**
* Data is a class to edit files.
* @author Madeleine Vigier
* @version 1.1
*/
public class Data {
private String pathRead;
public Data(String pathRead) {
this.pathRead = pathRead;
}
/**
* load() is a methode to split a file into lines, save lines in a arraylist
* @return Arraylist userlist
* @author Madeleine Vigier
* @version 1.1
*/
public ArrayList<User> readData() {
Path path = Paths.get(pathRead);
try {
List<String> rows = Files.readAllLines(path);
//muss noch angepasst werden
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 null;//menueList;
//ist angepasst
} else if (pathRead.equals("users.txt")){
ArrayList<User> 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;
//muss noch angepasst werden
} 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 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
* @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")) {
}
}
}

View File

@ -1,66 +0,0 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class Datei {
private String dataName;
public Datei(String dataName) {
this.dataName = dataName;
}
public User[] laden() {
Path pfad = Paths.get(dataName);
try {
List<String> zeilen = Files.readAllLines(pfad);
User[] userListe = new User[zeilen.size()];
for (int i = 0; i < zeilen.size(); i++) {
String[] teile = zeilen.get(i).split(":");
String nameParent1 = teile[0];
String nameParent2 = teile[1];
String billAddress = teile[2];
String phonenumber = teile[3];
String nameChildren = teile[4];
String password = teile[5];
userListe[i] = new User(nameParent1, nameParent2, billAddress, phonenumber, nameChildren, password);
}
return userListe;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
// public void speichern(Farbe[] farben, String dateiName) {
//
// Path pfad = Paths.get(dateiname);
//
// List<String> zeilen = new ArrayList<>();
// for (Farbe farbe : farben) {
// zeilen.add(farbe.formatieren());
//
// }
// try {
// Files.write(pfad, zeilen);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
}

View File

@ -6,8 +6,8 @@ import java.util.Scanner;
*/ */
public class Execute { public class Execute {
public static void main(String[] args) { public static void main(String[] args) {
Datei datei = new Datei("user.txt"); Data datei = new Data("users.txt");
User[] user = datei.laden(); ArrayList<User> user = datei.readData();
for (User user1 : user) { for (User user1 : user) {
System.out.println(user1); System.out.println(user1);
@ -16,20 +16,17 @@ public class Execute {
System.out.println("\t\t\tANMELDUNG"); System.out.println("\t\t\tANMELDUNG");
int i = 0; int i = 0;
Scanner leser = new Scanner(System.in); Scanner leser = new Scanner(System.in);
while (true) { while (true) {
System.out.print("Name: "); System.out.print("Name: ");
boolean error = false; boolean error = false;
String name = leser.nextLine(); String name = leser.nextLine();
if(name.isEmpty()){ error = isError(error, name);
error = true;
}
System.out.print("Passwort: "); System.out.print("Passwort: ");
String password = leser.nextLine(); String password = leser.nextLine();
if(password.isEmpty()){ error = isError(error, password);
error = true;
}
for (User user1 : user) { for (User user1 : user) {
@ -55,4 +52,11 @@ public class Execute {
} }
} }
} }
private static boolean isError(boolean error, String name) {
if (name.isEmpty()) {
error = true;
}
return error;
}
} }

View File

@ -1,3 +1,8 @@
/**
* User class creates users
* @author Madeleine Vigier
* @version 1.1
*/
public class User { public class User {
private String nameParent1; private String nameParent1;
private String nameParent2; private String nameParent2;
@ -6,6 +11,17 @@ public class User {
private String nameChildren; private String nameChildren;
private String password; private String password;
/**
* constructor
* @param nameParent1
* @param nameParent2
* @param billAddress
* @param phonenumber
* @param nameChildren
* @param password
* @author Madeleine Vigier
* @version 1.0
*/
public User(String nameParent1, String nameParent2, String billAddress, String phonenumber, String nameChildren, String password) { public User(String nameParent1, String nameParent2, String billAddress, String phonenumber, String nameChildren, String password) {
this.nameParent1 = nameParent1; this.nameParent1 = nameParent1;
this.nameParent2 = nameParent2; this.nameParent2 = nameParent2;
@ -15,22 +31,52 @@ public class User {
this.password = password; this.password = password;
} }
/**
* Methode getPhonenumber() gets the Phonenumber
* @return Phonenumber
* @author Madeleine Vigier
* @version 1.0
*/
public String getPhonenumber() { public String getPhonenumber() {
return phonenumber; return phonenumber;
} }
/**
* Methode getPassword() gets the password
* @return password
* @author Madeleine Vigier
* @version 1.0
*/
public String getPassword() { public String getPassword() {
return password; return password;
} }
/**
* Methode getNameParent1() gets nameParent1
* @return nameParent1
* @author Madeleine Vigier
* @version 1.0
*/
public String getNameParent1() { public String getNameParent1() {
return nameParent1; return nameParent1;
} }
/**
* Methode getNameParent2() gets nameParent2
* @return nameParent2
* @author Madeleine Vigier
* @version 1.0
*/
public String getNameParent2() { public String getNameParent2() {
return nameParent2; return nameParent2;
} }
/**
* Methode toString() returns a String representation of an object
* @return a String with nameParent1, nameparent2, billAdress, phonenumber, nameChildren, password
* @author Madeleine Vigier
* @version 1.0
*/
@Override @Override
public String toString() { public String toString() {
return "User{" + return "User{" +