code bereinigt, Methoden angepasst, java doc hinzugefügt
This commit is contained in:
parent
4f3522cf0e
commit
b8f0ebb121
Binary file not shown.
106
src/Data.java
Normal file
106
src/Data.java
Normal 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")) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
|
||||
}
|
@ -6,8 +6,8 @@ import java.util.Scanner;
|
||||
*/
|
||||
public class Execute {
|
||||
public static void main(String[] args) {
|
||||
Datei datei = new Datei("user.txt");
|
||||
User[] user = datei.laden();
|
||||
Data datei = new Data("users.txt");
|
||||
ArrayList<User> user = datei.readData();
|
||||
|
||||
for (User user1 : user) {
|
||||
System.out.println(user1);
|
||||
@ -16,20 +16,17 @@ public class Execute {
|
||||
System.out.println("\t\t\tANMELDUNG");
|
||||
int i = 0;
|
||||
Scanner leser = new Scanner(System.in);
|
||||
|
||||
while (true) {
|
||||
|
||||
|
||||
System.out.print("Name: ");
|
||||
boolean error = false;
|
||||
String name = leser.nextLine();
|
||||
if(name.isEmpty()){
|
||||
error = true;
|
||||
}
|
||||
error = isError(error, name);
|
||||
System.out.print("Passwort: ");
|
||||
String password = leser.nextLine();
|
||||
if(password.isEmpty()){
|
||||
error = true;
|
||||
}
|
||||
error = isError(error, password);
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,8 @@
|
||||
/**
|
||||
* User class creates users
|
||||
* @author Madeleine Vigier
|
||||
* @version 1.1
|
||||
*/
|
||||
public class User {
|
||||
private String nameParent1;
|
||||
private String nameParent2;
|
||||
@ -6,6 +11,17 @@ public class User {
|
||||
private String nameChildren;
|
||||
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) {
|
||||
this.nameParent1 = nameParent1;
|
||||
this.nameParent2 = nameParent2;
|
||||
@ -15,22 +31,52 @@ public class User {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode getPhonenumber() gets the Phonenumber
|
||||
* @return Phonenumber
|
||||
* @author Madeleine Vigier
|
||||
* @version 1.0
|
||||
*/
|
||||
public String getPhonenumber() {
|
||||
return phonenumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode getPassword() gets the password
|
||||
* @return password
|
||||
* @author Madeleine Vigier
|
||||
* @version 1.0
|
||||
*/
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode getNameParent1() gets nameParent1
|
||||
* @return nameParent1
|
||||
* @author Madeleine Vigier
|
||||
* @version 1.0
|
||||
*/
|
||||
public String getNameParent1() {
|
||||
return nameParent1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode getNameParent2() gets nameParent2
|
||||
* @return nameParent2
|
||||
* @author Madeleine Vigier
|
||||
* @version 1.0
|
||||
*/
|
||||
public String getNameParent2() {
|
||||
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
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
|
Loading…
Reference in New Issue
Block a user