Merge branch 'minor_adjustments'

api_adjustment
Selim Eser 2024-06-13 12:55:03 +02:00
commit 8abc7bda1b
6 changed files with 79 additions and 25 deletions

View File

@ -100,6 +100,9 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId> <artifactId>maven-pmd-plugin</artifactId>
<version>3.22.0</version> <version>3.22.0</version>
<configuration>
<failOnViolation>false</failOnViolation>
</configuration>
<executions> <executions>
<execution> <execution>
<phase>verify</phase> <phase>verify</phase>

View File

@ -81,6 +81,7 @@ public class System {
Double.parseDouble(fileString[7]))); Double.parseDouble(fileString[7])));
} }
} catch (Exception e) { } catch (Exception e) {
//
} }
} }
@ -110,7 +111,7 @@ public class System {
return false; return false;
} }
public boolean sign_up_user(String username, String password, String hometown, String zip, public boolean sign_up_user(String username, String password, String password_authentication, String hometown, String zip,
String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS){ String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS){
double car_l_100km; double car_l_100km;
@ -128,6 +129,9 @@ public class System {
if(username.equals("")||password.equals("")||hometown.equals("")||zip.equals("")) if(username.equals("")||password.equals("")||hometown.equals("")||zip.equals(""))
return false; return false;
if(!password.equals(password_authentication))
return false;
for(User user: this.all_user) for(User user: this.all_user)
if(user.getUsername().equals(username)) if(user.getUsername().equals(username))
return false; return false;
@ -170,7 +174,10 @@ public class System {
return false; return false;
} }
if(username.equals("")||password.equals("")||hometown.equals("")||zip.equals("")) if(!current_user.getPassword().equals(password))
return false;
if(username.equals("")||hometown.equals("")||zip.equals(""))
return false; return false;
for(User user: this.all_user) for(User user: this.all_user)
@ -208,6 +215,30 @@ public class System {
} }
public boolean change_user_password(String old_password, String new_password, String new_password_authentication){
if(!this.current_user.getPassword().equals(old_password))
return false;
if(!new_password.equals(new_password_authentication))
return false;
for(int i = 0; i< this.all_user.size(); i++)
if(this.all_user.get(i).getUsername().equals(current_user.getUsername()))
this.all_user.remove(i);
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.current_user.setPassword(new_password);
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<String> lines, String file) { public void write_to_file(ArrayList<String> lines, String file) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
for (int i = 0; i < lines.size() - 1; i++) { for (int i = 0; i < lines.size() - 1; i++) {
@ -215,7 +246,9 @@ public class System {
writer.newLine(); writer.newLine();
} }
writer.write(lines.getLast()); writer.write(lines.getLast());
} catch (IOException e) {} } catch (IOException e) {
//
}
} }
public void sign_out_user() { public void sign_out_user() {
@ -223,8 +256,8 @@ public class System {
} }
public String[] getDetails(){ public String[] getDetails(){
return new String[]{current_user.getUsername(), current_user.getPassword(), return new String[]{current_user.getUsername(), current_user.getHometown(),
current_user.getHometown(), current_user.getZip(), current_user.getCar_name(), current_user.getZip(), current_user.getCar_name(),
current_user.getCar_l_100km()==0?"":String.valueOf(current_user.getCar_l_100km()), 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.getCar_avg_kmh()==0?"":String.valueOf(current_user.getCar_avg_kmh()),
current_user.getBike_avg_kmh()==0?"":String.valueOf(current_user.getBike_avg_kmh())}; current_user.getBike_avg_kmh()==0?"":String.valueOf(current_user.getBike_avg_kmh())};
@ -244,6 +277,7 @@ public class System {
zip_set.add(line); zip_set.add(line);
} }
} catch (Exception e) { } catch (Exception e) {
//
} }
return new ArrayList<>(zip_set); return new ArrayList<>(zip_set);
@ -316,6 +350,7 @@ public class System {
weather = json.getJSONArray("weather").getJSONObject(0).getString("description"); weather = json.getJSONArray("weather").getJSONObject(0).getString("description");
temperature = json.getJSONObject("main").getDouble("temp"); temperature = json.getJSONObject("main").getDouble("temp");
} catch (Exception e) { } catch (Exception e) {
//
} }
if (weather.equals("")) if (weather.equals(""))
@ -390,6 +425,7 @@ public class System {
temperature_day_3_4 = json.getJSONArray("list").getJSONObject(30).getJSONObject("main").getDouble("temp"); temperature_day_3_4 = json.getJSONArray("list").getJSONObject(30).getJSONObject("main").getDouble("temp");
} catch (Exception e) { } catch (Exception e) {
//
} }
temperature_day_1.add(temperature_day_1_1); temperature_day_1.add(temperature_day_1_1);
@ -449,6 +485,7 @@ public class System {
} }
} }
} catch (Exception e) { } catch (Exception e) {
//
} }
InputStream inputStream2 = System.class.getResourceAsStream("/zip.csv"); InputStream inputStream2 = System.class.getResourceAsStream("/zip.csv");
@ -471,12 +508,13 @@ public class System {
distance = 6378.388 * 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a)); distance = 6378.388 * 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a));
result = Math.round((distance * 1.25) * 1000) / 1000.0; result = Math.round(distance * 1.25 * 1000) / 1000.0;
this.all_destinations.put(line.split(";")[0],new Destination(line.split(";")[1],line.split(";")[0], result)); this.all_destinations.put(line.split(";")[0],new Destination(line.split(";")[1],line.split(";")[0], result));
} }
} catch (Exception e) { } catch (Exception e) {
//
} }
return true; return true;
@ -492,15 +530,15 @@ public class System {
String[] result = new String[2]; String[] result = new String[2];
result[0] = "" + (Math.round(((Double.parseDouble(distance(destination_zip).replace(" km", "")) / current_user.getCar_avg_kmh())) * 1000) / 1000.0) + " h"; result[0] = "" + (Math.round(Double.parseDouble(distance(destination_zip).replace(" km", "")) / current_user.getCar_avg_kmh() * 1000) / 1000.0) + " h";
result[1] = "" + (Math.round(((Double.parseDouble(distance(destination_zip).replace(" km", "")) / current_user.getBike_avg_kmh())) * 1000) / 1000.0) + " h"; result[1] = "" + (Math.round(Double.parseDouble(distance(destination_zip).replace(" km", "")) / current_user.getBike_avg_kmh() * 1000) / 1000.0) + " h";
return result; return result;
} }
public String calc_l_consumption(String destination_zip) { public String calc_l_consumption(String destination_zip) {
return "" + (Math.round((Double.parseDouble(distance(destination_zip).replace(" km", "")) * (current_user.getCar_l_100km() / 100.0)) * 1000) / 1000.0) + " l"; return "" + (Math.round(Double.parseDouble(distance(destination_zip).replace(" km", "")) * current_user.getCar_l_100km() / 100.0 * 1000) / 1000.0) + " l";
} }
} }

View File

@ -16,9 +16,9 @@ public class Application {
return running_system.sign_in_user(username, password); return running_system.sign_in_user(username, password);
} }
public boolean sign_up_user(String username, String password, String hometown, String zip, public boolean sign_up_user(String username, String password, String password_authentication, String hometown, String zip,
String car_name, String car_co2_km, String car_avg_kmh, String bike_avg_kmh){ String car_name, String car_co2_km, String car_avg_kmh, String bike_avg_kmh){
return running_system.sign_up_user(username, password, hometown, zip, car_name, car_co2_km, car_avg_kmh, bike_avg_kmh); return running_system.sign_up_user(username, password, password_authentication, hometown, zip, car_name, car_co2_km, car_avg_kmh, bike_avg_kmh);
} }
public void sign_out_user(){ public void sign_out_user(){
@ -30,6 +30,10 @@ public class Application {
return running_system.change_user_details(username, password, hometown, zip, car_name, car_co2_km, car_avg_kmh, bike_avg_kmh); return running_system.change_user_details(username, password, hometown, zip, car_name, car_co2_km, car_avg_kmh, bike_avg_kmh);
} }
public boolean change_user_password(String old_password, String new_password, String new_password_authentication){
return running_system.change_user_password(old_password, new_password, new_password_authentication);
}
public ArrayList<String> search(String hometown_or_zip){ public ArrayList<String> search(String hometown_or_zip){
return running_system.search(hometown_or_zip); return running_system.search(hometown_or_zip);
} }

View File

@ -1,2 +1,2 @@
Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2 Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2
David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;300.0;20.0 David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;100.0;20.0
1 Daniel MTQwMURhbmllbA== Mannheim 68305 BMW 1.5 50.4 40.2
2 David MTIzRXNlbA== Mannheim 68161 AMG 10.0 300.0 100.0 20.0

View File

@ -51,9 +51,6 @@ public class SystemTest {
current_system.sign_in_user("David","123Esel"); current_system.sign_in_user("David","123Esel");
current_system.set_current_user_car_avg_kmh(100);
current_system.set_current_user_bike_avg_kmh(20);
assertEquals("0.885 h", current_system.travel_time("60306")[0]); // Frankfurt mit Auto assertEquals("0.885 h", current_system.travel_time("60306")[0]); // Frankfurt mit Auto
assertEquals("4.423 h", current_system.travel_time("60306")[1]); // Frankfurt mit Fahrrad assertEquals("4.423 h", current_system.travel_time("60306")[1]); // Frankfurt mit Fahrrad
@ -66,9 +63,6 @@ public class SystemTest {
current_system.sign_in_user("David","123Esel"); current_system.sign_in_user("David","123Esel");
current_system.set_current_user_car_avg_kmh(100);
current_system.set_current_user_car_l_100km(10);
assertEquals("8.846 l", current_system.calc_l_consumption("60306")); // Kraftstoffverbrauch nach Frankfurt assertEquals("8.846 l", current_system.calc_l_consumption("60306")); // Kraftstoffverbrauch nach Frankfurt
assertEquals("58.111 l", current_system.calc_l_consumption("20095")); // Kraftstoffverbrauch nach Hamburg assertEquals("58.111 l", current_system.calc_l_consumption("20095")); // Kraftstoffverbrauch nach Hamburg
assertEquals("60.361 l", current_system.calc_l_consumption("10115")); // Kraftstoffverbrauch nach Berlin assertEquals("60.361 l", current_system.calc_l_consumption("10115")); // Kraftstoffverbrauch nach Berlin
@ -129,29 +123,44 @@ public class SystemTest {
@Test @Test
public void sign_up_user(){ public void sign_up_user(){
// Username darf nicht doppelt vorkommen! // Username darf nicht doppelt vorkommen!
assertEquals(false, current_system.sign_up_user("David","123Esel","Mannheim","68161","AMG","10","300","20")); assertEquals(false, current_system.sign_up_user("David","123Esel","123Esel","Mannheim","68161","AMG","10","300","20"));
assertEquals(true, current_system.sign_up_user("Selim","Penis69","Mannheim","68161","AMG","10","300","20")); assertEquals(true, current_system.sign_up_user("Selim","Penis69","Penis69","Mannheim","68161","AMG","10","300","20"));
// PLZ muss mit Stadt übereinstimmen // PLZ muss mit Stadt übereinstimmen
assertEquals(false, current_system.sign_up_user("Lukas","123Esel","Mannheim","11105","AMG","10","300","20")); assertEquals(false, current_system.sign_up_user("Lukas","123Esel","123Esel","Mannheim","11105","AMG","10","300","20"));
assertEquals(true, current_system.sign_up_user("Lukas","123Esel","Mannheim","68305","AMG","10","300","20")); assertEquals(true, current_system.sign_up_user("Lukas","123Esel","123Esel","Mannheim","68305","AMG","10","300","20"));
assertEquals("Lukas",current_system.getDetails()[0]); assertEquals("Lukas",current_system.getDetails()[0]);
current_system.sign_out_user(); current_system.sign_out_user();
assertEquals("",current_system.getDetails()[0]); assertEquals("",current_system.getDetails()[0]);
assertEquals(true, current_system.sign_in_user("Lukas","123Esel"));
} }
@Test @Test
public void change_user_details(){ public void change_user_details(){
current_system.sign_in_user("David", "123Esel"); current_system.sign_in_user("David", "123Esel");
current_system.change_user_details("Enes", "Penis123", "Mannheim", "68161", "", "", "", ""); current_system.change_user_details("Enes", "123Esel", "Mannheim", "68161", "", "", "", "");
assertEquals("Enes", current_system.getDetails()[0]); assertEquals("Enes", current_system.getDetails()[0]);
current_system.change_user_details("David", "123Esel", "Mannheim", "68161", "AMG", "10", "100", "20");
}
@Test
public void change_user_password(){
current_system.sign_in_user("David", "123Esel");
assertEquals(true, current_system.change_user_password("123Esel", "Pizza69", "Pizza69"));
assertEquals(true, current_system.change_user_password("Pizza69", "123Esel", "123Esel"));
assertEquals(true, current_system.change_user_details("Enes", "123Esel", "Mannheim", "68161", "", "", "", ""));
current_system.change_user_details("David", "123Esel", "Mannheim", "68161", "AMG", "10", "100", "20");
;
} }
/* /*
Tests auf Basis von user_data.csv: Tests auf Basis von user_data.csv:
Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2 Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2
David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;300.0;20.0 David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;100.0;20.0
*/ */

View File

@ -1,2 +1,2 @@
Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2 Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2
David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;300.0;20.0 David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;100.0;20.0
1 Daniel MTQwMURhbmllbA== Mannheim 68305 BMW 1.5 50.4 40.2
2 David MTIzRXNlbA== Mannheim 68161 AMG 10.0 300.0 100.0 20.0