diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index ab7c799..fc3c47c 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -96,6 +96,38 @@ public class System { return false; } + public boolean sign_up_user(String username, String password, String hometown, String zipS, + String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS){ + + int zip = Integer.parseInt(zipS); + double car_l_100km = Double.parseDouble(car_l_100kmS); + double car_avg_kmh = Double.parseDouble(car_avg_kmhS); + double bike_avg_kmh = Double.parseDouble(bike_avg_kmhS); + + ArrayList all_user = get_all_user(); + + for(User user: all_user) + if(user.getUsername().equals(username)) + return false; + + ArrayList mem = search(zipS); + boolean bool = false; + + for (String line: mem) + if(line.split(";")[1].equals(hometown)) { + bool = true; + break; + } + + if(!bool) + return false; + + current_user = new User(username, password, hometown, zip, car_name, car_l_100km, car_avg_kmh, bike_avg_kmh); + + + + return true; + } /*public boolean sign_up_user(String username, String password, String hometown, String zipS, String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS) throws IOException { diff --git a/src/test/java/de/hs_mannheim/domain/SystemTest.java b/src/test/java/de/hs_mannheim/domain/SystemTest.java index a804e42..4d9100f 100644 --- a/src/test/java/de/hs_mannheim/domain/SystemTest.java +++ b/src/test/java/de/hs_mannheim/domain/SystemTest.java @@ -131,6 +131,17 @@ public class SystemTest { } + @Test + public void sign_up_user(){ + // Username darf nicht doppelt vorkommen! + assertEquals(false, current_system.sign_up_user("David","123Esel","Mannheim","68161","AMG","10","300","20")); + assertEquals(true, current_system.sign_up_user("Daavid","123Esel","Mannheim","68161","AMG","10","300","20")); + // PLZ muss mit Stadt übereinstimmen + assertEquals(false, current_system.sign_up_user("Lukas","123Esel","Mannheim","11105","AMG","10","300","20")); + assertEquals(true, current_system.sign_up_user("Lukas","123Esel","Mannheim","68305","AMG","10","300","20")); + + } +