VPR-Projekt/src/Login.java

70 lines
2.3 KiB
Java
Raw Normal View History

2022-12-20 19:12:54 +01:00
import java.util.ArrayList;
2022-12-20 19:41:12 +01:00
import java.util.Scanner;
2022-12-20 19:12:54 +01:00
public class Login {
/**
* The method toLogin() compares the phonenumber and password of the user with the phonenumber and password
* from the user.txt
*
* @param user all users are in a list
* @param password password of the user
* @param phoneNumber phonenumber of the user
* @return void
* @author Kevin Pfannenstiel
*/
public void toLogin(ArrayList<User> user, String password, String phoneNumber) {
2022-12-20 19:12:54 +01:00
2022-12-20 19:41:12 +01:00
Scanner leser = new Scanner(System.in);
2022-12-21 08:28:06 +01:00
System.out.println();
int i = 0;
while (true) {
boolean error = false;
error = isError(error, phoneNumber);
for (User user1 : user) {
if (!error) {
if (user1.getPassword().equals(password) && user1.getPhonenumber().equals(phoneNumber)) {
System.out.println("");
System.out.println("\t\t\tANMELDUNG");
System.out.println();
System.out.println("Herzlich Willkommen " + user1.getNameParent1() + " und " + user1.getNameParent2() + ", Ihr Login war erfolgreich!");
i++;
break;
}
else if (!(user1.getPassword().equals(password) && user1.getPhonenumber().equals(phoneNumber))) {
System.out.println("Login fehlgeschlagen. Versuchen Sie es erneut.");
System.out.println("");
System.out.print("Telefonnummer: ");
phoneNumber = leser.nextLine();
System.out.print("Passwort: ");
password = leser.nextLine();
break;
2022-12-20 19:12:54 +01:00
}
}
2022-12-21 08:28:06 +01:00
}
if (i > 0) {
break;
2022-12-20 19:12:54 +01:00
}
}
}
2022-12-21 08:28:06 +01:00
/**
* The method getDayNumberNew() checks if the phonenumber-input is empty.
*
* @param error is a boolean
* @param phoneNumber is the input of the user
* @return the boolean error
* @author Madeleine Vigier
*/
2022-12-21 08:28:06 +01:00
public boolean isError(boolean error, String phoneNumber) {
if (phoneNumber.isEmpty()) {
error = true;
}
2022-12-20 19:12:54 +01:00
return error;
}
}