diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 7805f5c..36ed716 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -108,7 +108,7 @@ public class System { double car_avg_kmh = Double.parseDouble(car_avg_kmhS); double bike_avg_kmh = Double.parseDouble(bike_avg_kmhS); - for(User user: all_user) + for(User user: this.all_user) if(user.getUsername().equals(username)) return false; @@ -134,6 +134,57 @@ public class System { return true; } + public boolean change_user_details(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; + double car_l_100km; + double car_avg_kmh; + double bike_avg_kmh; + + try{ + zip = Integer.parseInt(zipS); + car_l_100km = Double.parseDouble(car_l_100kmS); + car_avg_kmh = Double.parseDouble(car_avg_kmhS); + bike_avg_kmh = Double.parseDouble(bike_avg_kmhS); + } catch (NumberFormatException n){ + return false; + } + + if(username.equals("")||password.equals("")||hometown.equals("")||zipS.equals("")) + return false; + + for(User user: this.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; + + this.all_user.remove(this.current_user); + this.current_user = new User(username, password, hometown, zip, car_name, car_l_100km, car_avg_kmh, bike_avg_kmh); + + write_to_file(all_user_toString(), "src/main/resources/user_data.csv"); + write_to_file(all_user_toString(), "src/test/resources/user_data.csv"); + + this.all_user.add(current_user); + + write_to_file(all_user_toString(), "src/main/resources/user_data.csv"); + write_to_file(all_user_toString(), "src/test/resources/user_data.csv"); + + return true; + + } + public void write_to_file(ArrayList lines, String file) { try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { for (int i = 0; i < lines.size() - 1; i++) { @@ -152,9 +203,12 @@ public class System { public String[] getDetails(){ return new String[]{current_user.getUsername(), current_user.getPassword(), - current_user.getHometown(), String.valueOf(current_user.getZip()), - current_user.getCar_name(), String.valueOf(current_user.getCar_l_100km()), - String.valueOf(current_user.getCar_avg_kmh()), String.valueOf(current_user.getCar_avg_kmh())}; + current_user.getHometown(), + current_user.getZip()==0?"":String.valueOf(current_user.getZip()), + current_user.getCar_name(), + current_user.getCar_l_100km()==0?"":String.valueOf(current_user.getCar_l_100km()), + current_user.getCar_avg_kmh()==0?"":String.valueOf(current_user.getCar_avg_kmh()), + current_user.getBike_avg_kmh()==0?"":String.valueOf(current_user.getBike_avg_kmh())}; } public ArrayList search(String hometown_or_zip) { diff --git a/src/test/java/de/hs_mannheim/domain/SystemTest.java b/src/test/java/de/hs_mannheim/domain/SystemTest.java index aa5a7a6..666c72b 100644 --- a/src/test/java/de/hs_mannheim/domain/SystemTest.java +++ b/src/test/java/de/hs_mannheim/domain/SystemTest.java @@ -3,7 +3,6 @@ package de.hs_mannheim.domain; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; -import java.io.IOException; import java.util.ArrayList; import org.junit.jupiter.api.Test; @@ -123,7 +122,7 @@ public class SystemTest { } - @Test + /*@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")); @@ -135,6 +134,15 @@ public class SystemTest { assertEquals("Lukas",current_system.getDetails()[0]); current_system.sign_out_user(); assertEquals("",current_system.getDetails()[0]); + }*/ + + @Test + public void change_user_details(){ + + current_system.sign_in_user("David", "123Esel"); + current_system.change_user_details(null, null, null, null, null, null, null, null); + assertEquals(current_system, STR); + }