Compare commits

..

115 Commits

Author SHA1 Message Date
Selim Eser 11797b9b73 Merge branch 'bugfix_branch' 2024-06-18 18:13:45 +02:00
Selim Eser af6e9669b4 Removed redundant gui Code and fixed some texts 2024-06-18 18:10:49 +02:00
David Groys b92c488768 Dateien nach "/" hochladen 2024-06-18 11:01:35 +02:00
Selim Eser 7acdaf97a4 Merge branch 'bugfix_branch' 2024-06-18 07:15:31 +02:00
Selim Eser c6a209e27e fancy gui 2024-06-18 07:14:12 +02:00
Selim Eser 10fb4ac11c Minor changes 2024-06-16 23:07:27 +02:00
Selim Eser 5215d9b4f7 Some gui displayed text changes 2024-06-16 22:55:02 +02:00
Selim Eser e0cd0c376f current_weather and weather_forecast method fix for zips under length of 5 2024-06-16 21:53:05 +02:00
Selim Eser 0060368e0a search method comparison logic fixed 2024-06-16 21:42:41 +02:00
Selim Eser 9dc98f62e7 change_user_password method now needs to take a new password otherwise will return false 2024-06-16 21:38:24 +02:00
Selim Eser 00a96494e6 icons fix 2024-06-16 21:29:47 +02:00
David Groys f9fb48a3f4 Merge branch 'gui' 2024-06-16 16:49:24 +02:00
David Groys 606708c904 Fixed minor visual bug, final commit 2024-06-16 15:59:39 +02:00
David Groys b34b0c82bc Gui complete, I cooked 2024-06-16 15:51:20 +02:00
David Groys 5ce975c334 implemented the change details panel to show former details excpet password 2024-06-16 15:28:01 +02:00
David Groys 991e0f1d8d implemented reset of textfields so that data doesnt leak 2024-06-16 15:28:01 +02:00
David Groys d08992eba2 changed destination details creation a little 2024-06-16 15:28:01 +02:00
David Groys b670cc38dc changed profile creation a little 2024-06-16 15:28:00 +02:00
David Groys 1a45bc23ec implemented scrollbar with search results with error message if none are found 2024-06-16 15:28:00 +02:00
David Groys 5eaff1161b small visual bug fix 2024-06-16 15:28:00 +02:00
David Groys ed04821220 implemented change password Button and panel (both functional) 2024-06-16 15:28:00 +02:00
David Groys d45465c1ad implemented change details Button and panel (both functional) but found minor error in Backend, when u want to change details u currently NEED to change name, this is not intended 2024-06-16 15:28:00 +02:00
David Groys 47e613d109 included error message 2024-06-16 15:28:00 +02:00
David Groys 89961cfca9 changed a few things (because pulled methods from System class were changed) no new functions 2024-06-16 15:28:00 +02:00
David Groys 109489f0ad Implemented User shown on Gugl Panel and functional registration, login and logout 2024-06-16 15:28:00 +02:00
David Groys c182602dfa started (not tested) the search Button implementation 2024-06-16 15:28:00 +02:00
David Groys 1028a91a47 started implementing buttons for detinations 2024-06-16 15:28:00 +02:00
David Groys 0d76243379 getDetails() changeUserDetails() und sign_up_user() (erneut) angepasst 2024-06-16 15:27:59 +02:00
David Groys 89c767f5c9 registerConfirmButton Action Listener implemented and fixed issue in getTextfieldContent() 2024-06-16 15:27:59 +02:00
David Groys 11db856157 loginConfirmButton Action Listener implemented 2024-06-16 15:27:59 +02:00
David Groys 9bdae273d8 first (maybe last) commit of User pofile which is shown on app Panel 2024-06-16 15:27:59 +02:00
David Groys 316222e8b5 Cosmetic changes to most panels 2024-06-16 15:27:59 +02:00
David Groys d803f6df2a Added components to App Panel 2024-06-16 15:27:59 +02:00
David Groys 1e7bb5cdfe completed App Panel and its components 2024-06-16 15:27:59 +02:00
David Groys f8c35aca98 completed Register Panel and its components 2024-06-16 15:27:59 +02:00
David Groys 8f5211a5ef completed Login Panel and its components 2024-06-16 15:27:59 +02:00
David Groys 6090029284 completed LogReg Panel and its components 2024-06-16 15:27:58 +02:00
David Groys 8d83fc784c organized PanleLayout and initialized attributes in corresponding methods 2024-06-16 15:27:58 +02:00
David Groys 4a3c4dbcea TODO Methods generated, initialize method preplaned, constructor implemented 2024-06-16 15:27:58 +02:00
David Groys 30d805e17d initial GUI 2024-06-16 15:27:57 +02:00
selim 751a3c7117 Merge branch 'bugfix_branch' 2024-06-16 15:10:07 +02:00
selim 592a22fbd8 destination_details method index fix 2024-06-16 15:09:26 +02:00
selim 0f1dea7bec Merge branch 'bugfix_branch' 2024-06-16 05:30:46 +02:00
selim d3a7b96213 Adjusted System Tests to new returns 2024-06-16 05:29:59 +02:00
selim c0ac21148f weather_forecast output slightly adjusted 2024-06-16 05:18:33 +02:00
selim a5d53ac895 travel_time method divided by 0 fix and current_weather, weather_forecast methods different return 2024-06-16 05:18:33 +02:00
Selim Eser 0c1b1fbe76 Merge branch 'bugfix_branch' 2024-06-14 21:11:16 +02:00
Selim Eser 3bde666802 change_user_details method username change logic fixed 2024-06-14 21:07:31 +02:00
Selim Eser a78f0bd47e Merge branch 'api_adjustment' 2024-06-13 17:54:14 +02:00
Selim Eser c8344e3bf2 current_weather return String slightly adjusted 2024-06-13 17:53:37 +02:00
Selim Eser 5da483b279 weather_forecast improved by more and more precise time stamps 2024-06-13 17:50:30 +02:00
Selim Eser 8abc7bda1b Merge branch 'minor_adjustments' 2024-06-13 12:55:03 +02:00
Selim Eser b66b2314d8 sign_up_user method now requires password authentication 2024-06-13 12:54:33 +02:00
Selim Eser a2e432119e change_user_password method implemented and tested successful 2024-06-13 12:48:33 +02:00
Selim Eser 7df63b10ed change_user_details require correct password input in order to change 2024-06-13 12:23:56 +02:00
Selim Eser b71f9c090a getDetails method shouldnt return password fix 2024-06-13 12:21:08 +02:00
Selim Eser ed2acc0065 Fixed some pmd violations and made the build successful after checking the rest 2024-06-12 01:30:09 +02:00
Selim Eser f90eeb6841 Removed unnecessary code in tests 2024-06-12 00:16:46 +02:00
Selim Eser a38c77533a Tests fixed to automatically correcting user_data.csv 2024-06-12 00:08:30 +02:00
Selim Eser 31a24b8c9a Merge branch 'destination_runtime_improvement' 2024-06-11 23:57:41 +02:00
Selim Eser a366b27ee3 Everything fixed tests successful 2024-06-11 23:56:48 +02:00
Selim Eser d366227c52 Finished implementing 2024-06-11 23:04:38 +02:00
Selim Eser 531407dcf7 Added calculation method for all Destinations from current_user zip 2024-06-11 22:39:07 +02:00
Selim Eser d5408617e1 Destination.java created in order to calc all destination distances once 2024-06-11 22:11:11 +02:00
David Groys ca8f9a0053 Merge branch 'application' 2024-06-11 16:08:57 +02:00
David Groys 6acdf13340 implemented missing returns. 2024-06-11 16:07:43 +02:00
David Groys 4335e7f49e distance method implemented 2024-06-11 16:00:44 +02:00
David Groys 9ceffc108d getDetails() changeUserDetails() und signUoUser() angepasst 2024-06-11 16:00:44 +02:00
David Groys a8cac6b067 get_details method implemented 2024-06-11 16:00:44 +02:00
Selim Eser 1a8f2bfa74 Merge branch 'sign_in_up_out' 2024-06-11 15:56:39 +02:00
Selim Eser 122dfe0b64 Merge branch 'selims_dev_branch' into sign_in_up_out 2024-06-11 15:55:42 +02:00
Selim Eser 0cd0be5fe9 Everything works fine for now tests all successful 2024-06-11 15:53:54 +02:00
Selim Eser 4a811935d2 More Exception Handling 2024-06-11 15:13:37 +02:00
Selim Eser 0e4f7d35b7 change_user_details method implemented and getDetails Exception Handling 2024-06-11 15:07:35 +02:00
Selim Eser f669e91668 sign_out_method fixed all tests successful 2024-06-11 14:32:24 +02:00
Daniel Zdravkovic bc8c19bc66 all_user_toString method and write_to_file method implemented to help with sign_up_user 2024-06-11 11:54:07 +02:00
Daniel Zdravkovic 735c1f38ea more tests for sign_up successful 2024-06-11 11:37:06 +02:00
Daniel Zdravkovic cd86769cd0 first sign_up_method logic implemented and tested successful 2024-06-11 11:34:42 +02:00
Daniel Zdravkovic 675a1bd35e more sign_out tests 2024-06-11 11:11:59 +02:00
Daniel Zdravkovic 8bf5c4a0b8 sign_out_method tests successful 2024-06-11 11:09:29 +02:00
Daniel Zdravkovic 6252c3d686 sign_in_user method another minor decoding fix and tests successful 2024-06-11 11:05:48 +02:00
Daniel Zdravkovic 5141d8ec03 sign_in_user method minor change 2024-06-11 11:00:28 +02:00
Daniel Zdravkovic 5d087518e9 get_all_user tests successful 2024-06-11 10:57:28 +02:00
Daniel Zdravkovic 33ff251c20 decoding encoding methods fixed and tests successful/ sign_up some other minor needs to be worked over 2024-06-11 10:50:46 +02:00
Daniel Zdravkovic 75b3b597c1 get_all_user method, sign_in_up methods fixed and get_all_user method successfully tested 2024-06-10 15:58:06 +02:00
Daniel Zdravkovic 8016e9848e sign_up method implemented 2024-06-10 15:21:54 +02:00
Daniel Zdravkovic 0a1482451f encoding / decoding method fix 2024-06-10 15:19:24 +02:00
Daniel Zdravkovic 96e7dad23f sign_up_user implemented and new logic for csv data 2024-06-10 15:17:36 +02:00
Daniel Zdravkovic f5e74fbbe5 discard some useless dependencies 2024-06-10 15:05:01 +02:00
Daniel Zdravkovic 52ed99fc1d sign_out_user method implemented 2024-06-10 14:44:55 +02:00
Daniel Zdravkovic 88493290fd sign_in_user method implemented 2024-06-10 14:40:53 +02:00
Daniel Zdravkovic 359a88b773 Merge branch 'get_all_user' 2024-06-10 14:38:13 +02:00
Daniel Zdravkovic 41676607ad createSheet Methode welche eine Tabelle erstellt mit User Informationen 2024-06-10 14:37:46 +02:00
Daniel Zdravkovic 5120dd94be encoding und decoding methods mit Base64 implementiert 2024-06-10 14:37:46 +02:00
Daniel Zdravkovic a41384a116 get_all_users method (complete but without encoding method) 2024-06-10 14:37:46 +02:00
Selim Eser 79b145e9f5 System minor inputstream fix 2024-06-10 14:01:37 +02:00
Selim Eser f17f4d1a1c Merge branch 'random_destinations_fix' 2024-06-09 21:55:16 +02:00
Selim Eser 4fbcfb4bf5 If user signs out the saved distances get deleted 2024-06-09 21:54:50 +02:00
Selim Eser e2923ae838 System.java now saves all distances after one calculation to fasten random_destinations methods up 2024-06-09 21:51:37 +02:00
Selim Eser 1aed134131 Corrected the method logic 2024-06-09 21:15:39 +02:00
Selim Eser 5a6fe3fc53 Merge branch 'facade_class' 2024-06-09 20:26:52 +02:00
Selim Eser 9c6ed4b889 Enabled Static code analysis 2024-06-09 20:26:24 +02:00
Selim Eser 372745939c Application.java includes all System methods without the user methods now 2024-06-09 20:23:12 +02:00
Selim Eser 8c2eba6d48 Fixed some problems 2024-06-09 20:17:02 +02:00
Selim Eser de917666c7 Merge branch 'distance_related_methods' 2024-06-09 20:01:53 +02:00
Selim Eser 0ac411e9d3 Fixed search, random_destination method return ArrayList sizes, implemented random_destination tests and build ran successful 2024-06-09 19:59:22 +02:00
Selim Eser db04ad8201 calc_l_consumption method test implemented and successful 2024-06-09 19:36:53 +02:00
Selim Eser 3b49d9f2e2 Added Rounding in double methods for 3 decimal places, updated method tests, implemented travel_time method test and all tests run successful 2024-06-09 19:30:50 +02:00
Selim Eser ba7ba72a87 Added some Exception Handling 2024-06-09 18:58:41 +02:00
Selim Eser e3ae9c6599 destination_details method implemented 2024-06-09 18:45:42 +02:00
Selim Eser 9deda6bf76 random_destinations_bike method implemented 2024-06-09 18:39:48 +02:00
Selim Eser 44b385bf3d random_destinations_car method implemented 2024-06-09 18:38:38 +02:00
Selim Eser 5413a18435 Changed car_co2_km to car_l_100km because its more important for user and implemented calc_l_consumption 2024-06-09 18:25:57 +02:00
Selim Eser 5a5f86db98 travel_time method implemented 2024-06-09 18:12:54 +02:00
Selim Eser 7439e5159c Merge branch 'distance_method' 2024-06-09 18:01:01 +02:00
14 changed files with 2130 additions and 166 deletions

3
README.txt 100644
View File

@ -0,0 +1,3 @@
Selim Eser 2211482: Selim Eser, Selim
David Groys 3012642: David Groys
Daniel Zdravkovic 3012893: Daniel Zdravkovic

12
pom.xml
View File

@ -28,6 +28,11 @@
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20210307</version> <version>20210307</version>
</dependency> </dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.17.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<resources> <resources>
@ -90,11 +95,14 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<!-- Static code analysis, cf: target/site/pmd.html <!-- Static code analysis, cf: target/site/pmd.html -->
<plugin> <plugin>
<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>
@ -103,7 +111,7 @@
</goals> </goals>
</execution> </execution>
</executions> </executions>
</plugin>--> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -0,0 +1,36 @@
package de.hs_mannheim.domain;
public class Destination {
private String town;
private String zip;
private double distance_from_user;
public Destination(String town,String zip, double distance_from_user) {
this.town = town;
this.zip = zip;
this.distance_from_user = distance_from_user;
}
public String getTown() {
return town;
}
public void setTown(String town) {
this.town = town;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public double getDistance_from_user() {
return distance_from_user;
}
public void setDistance_from_user(double distance_from_user) {
this.distance_from_user = distance_from_user;
}
}

View File

@ -1,124 +1,398 @@
package de.hs_mannheim.domain; package de.hs_mannheim.domain;
import java.io.BufferedReader; import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI; import java.net.URI;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers; import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashMap;
import java.util.TreeSet; import java.util.TreeSet;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONObject; import org.json.JSONObject;
import de.hs_mannheim.ui.Main;
public class System { public class System {
private User current_user = new User(); private User current_user = new User();
private ArrayList<User> all_user = new ArrayList<>();
private String api_key; private String api_key;
private HashMap<String, Destination> all_destinations = new HashMap<String, Destination>();
public System(String api_key) { public System(String api_key) {
this.api_key = api_key; this.api_key = api_key;
get_all_user();
} }
public void set_current_user_zip(String zip){ public void set_current_user_zip(String zip) {
this.current_user.setZip(Integer.parseInt(zip)); this.current_user.setZip(zip);
} }
public HashSet<User> get_all_user(){ public void set_current_user_car_l_100km(double car_l_100km) {
return new HashSet<User>(); this.current_user.setCar_l_100km(car_l_100km);
} }
public boolean sign_in_user(String username, String password){ public void set_current_user_car_avg_kmh(double car_avg_kmh) {
this.current_user.setCar_avg_kmh(car_avg_kmh);
}
public void set_current_user_bike_avg_kmh(double bike_avg_kmh) {
this.current_user.setBike_avg_kmh(bike_avg_kmh);
}
public static String decoding(String string) {
byte[] binary_data = new byte[string.length()];
for (int i = 0; i < string.length(); i++) {
binary_data[i] = (byte) string.charAt(i);
}
return new String(Base64.decodeBase64(binary_data));
}
public static String encoding(String string) {
byte[] binary_data = new byte[string.length()];
for (int i = 0; i < string.length(); i++) {
binary_data[i] = (byte) string.charAt(i);
}
return Base64.encodeBase64String(binary_data);
}
public static double parseDouble(String s) throws NumberFormatException {
if (s.equals(""))
return 0;
else
return Double.parseDouble(s);
}
public void get_all_user() {
String[] fileString = new String[8];
InputStream inputStream = System.class.getResourceAsStream("/user_data.csv");
String path;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
while ((path = reader.readLine()) != null) {
fileString = path.split(";");
fileString[1] = decoding(fileString[1]);
this.all_user.add(new User(fileString[0], fileString[1], fileString[2],
fileString[3], fileString[4],
Double.parseDouble(fileString[5]),
Double.parseDouble(fileString[6]),
Double.parseDouble(fileString[7])));
}
} catch (Exception e) {
//
}
}
public ArrayList<String> all_user_toString() {
ArrayList<String> result = new ArrayList<>();
for (User user : this.all_user) {
result.add(user.toString());
}
return result;
}
public boolean sign_in_user(String username, String password) {
for (User user : this.all_user) {
if (user.getUsername().equals(username) && user.getPassword().equals(password)) {
current_user = new User(user.getUsername(), user.getPassword(),
user.getHometown(), user.getZip(), user.getCar_name(),
user.getCar_l_100km(), user.getCar_avg_kmh(), user.getBike_avg_kmh());
all_distances();
return true;
}
}
return false;
}
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) {
double car_l_100km;
double car_avg_kmh;
double bike_avg_kmh;
try {
car_l_100km = parseDouble(car_l_100kmS);
car_avg_kmh = parseDouble(car_avg_kmhS);
bike_avg_kmh = parseDouble(bike_avg_kmhS);
} catch (NumberFormatException n) {
return false;
}
if (username.equals("") || password.equals("") || hometown.equals("") || zip.equals(""))
return false;
if (!password.equals(password_authentication))
return false;
for (User user : this.all_user)
if (user.getUsername().equals(username))
return false;
ArrayList<String> mem = search(zip);
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);
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");
all_distances();
return true; return true;
} }
public boolean sign_up_user(String username, String password, String hometown, int zip, public boolean change_user_details(String username, String password, String hometown, String zip,
String car_name, double car_co2_km, double car_avg_kmh, double bike_avg_kmh){ String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS) {
double car_l_100km;
double car_avg_kmh;
double bike_avg_kmh;
try {
car_l_100km = parseDouble(car_l_100kmS);
car_avg_kmh = parseDouble(car_avg_kmhS);
bike_avg_kmh = parseDouble(bike_avg_kmhS);
} catch (NumberFormatException n) {
return false;
}
if (!current_user.getPassword().equals(password))
return false;
if (username.equals("") || hometown.equals("") || zip.equals(""))
return false;
if (!current_user.getUsername().equals(username)) {
for (User user : this.all_user)
if (user.getUsername().equals(username))
return false;
}
ArrayList<String> mem = search(zip);
boolean bool = false;
for (String line : mem)
if (line.split(";")[1].equals(hometown)) {
bool = true;
break;
}
if (!bool)
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 = new User(username, password, hometown, zip, car_name, car_l_100km, car_avg_kmh,
bike_avg_kmh);
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");
all_distances();
return true; return true;
} }
public void sign_out_user(){} 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;
if(old_password.equals(new_password))
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");
public boolean change_user_details(String username, String password, String hometown, int zip,
String car_name, double car_co2_km, double car_avg_kmh, double bike_avg_kmh){
return true; return true;
} }
public ArrayList<String> search(String hometown_or_zip){ public void write_to_file(ArrayList<String> lines, String file) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
for (int i = 0; i < lines.size() - 1; i++) {
writer.write(lines.get(i));
writer.newLine();
}
writer.write(lines.getLast());
} catch (IOException e) {
//
}
}
public void sign_out_user() {
current_user = new User();
}
public String[] getDetails() {
return new String[] { current_user.getUsername(), current_user.getHometown(),
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<String> search(String hometown_or_zip) {
TreeSet<String> zip_set = new TreeSet<>(); TreeSet<String> zip_set = new TreeSet<>();
InputStream inputStream = Main.class.getResourceAsStream("/zip.csv"); InputStream inputStream = System.class.getResourceAsStream("/zip.csv");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null && zip_set.size() < 200) {
if(line.contains(hometown_or_zip)&&zip_set.size()<200){ line = line.replace("\"", "");
line = line.replace("\"", ""); if (line.split(";")[0].toUpperCase().startsWith(hometown_or_zip.toUpperCase())
|| line.split(";")[1].toUpperCase().startsWith(hometown_or_zip.toUpperCase()))
zip_set.add(line); zip_set.add(line);
}
} }
} catch (Exception e) {} } catch (Exception e) {
//
}
return new ArrayList<>(zip_set); return new ArrayList<>(zip_set);
} }
public ArrayList<String> random_destinations_car(){ public ArrayList<String> random_destinations_car() {
return new ArrayList<String>();
ArrayList<Destination> mem = new ArrayList<>();
ArrayList<String> result = new ArrayList<>();
int random = 0;
for (Destination destination : this.all_destinations.values()) {
if (destination.getDistance_from_user() > 150)
mem.add(destination);
}
for (int i = 0; i < 3; i++) {
random = (int) (Math.random() * mem.size());
result.add(mem.get(random).getZip() + ";" + mem.get(random).getTown());
}
return result;
} }
public ArrayList<String> random_destinations_bike(){ public ArrayList<String> random_destinations_bike() {
return new ArrayList<String>();
ArrayList<Destination> mem = new ArrayList<>();
ArrayList<String> result = new ArrayList<>();
int random = 0;
for (Destination destination : this.all_destinations.values()) {
if (destination.getDistance_from_user() < 100)
mem.add(destination);
}
for (int i = 0; i < 3; i++) {
random = (int) (Math.random() * mem.size());
result.add(mem.get(random).getZip() + ";" + mem.get(random).getTown());
}
return result;
} }
public String[] destination_details(String destination_zip){ public String[] destination_details(String destination_zip) {
return new String[1]; String[] result = new String[7];
result[0] = weather_forecast(destination_zip)[0]; // Wettervorhersage für die nächsten 3 Tage
result[1] = weather_forecast(destination_zip)[1];
result[2] = weather_forecast(destination_zip)[2];
result[3] = distance(destination_zip); // Entfernung
result[4] = travel_time(destination_zip)[0]; // Reisedauer Auto
result[5] = calc_l_consumption(destination_zip); // Kraftstoffverbrauch Auto
result[6] = travel_time(destination_zip)[1]; // Reisedauer Fahrrad
return result;
} }
public String current_weather(){ public String current_weather() {
String weather = ""; String weather = "";
double temperature = 1; double temperature = 1;
try{ try {
HttpClient http_client = HttpClient.newHttpClient(); HttpClient http_client = HttpClient.newHttpClient();
HttpRequest get_request;
HttpRequest get_request = HttpRequest.newBuilder()
.uri(new URI("https://api.openweathermap.org/data/2.5/weather?zip="+current_user.getZip()+",de&appid="+api_key+"&units=metric&lang=de")) if(current_user.getZip().length()<5){
.GET() get_request = HttpRequest.newBuilder()
.build(); .uri(new URI("https://api.openweathermap.org/data/2.5/weather?q=" + current_user.getHometown()
+ ",de&appid=" + api_key + "&units=metric&lang=de"))
HttpResponse get_response = http_client.send(get_request, BodyHandlers.ofString()); .GET()
.build();
}
else{
get_request = HttpRequest.newBuilder()
.uri(new URI("https://api.openweathermap.org/data/2.5/weather?zip=" + current_user.getZip()
+ ",de&appid=" + api_key + "&units=metric&lang=de"))
.GET()
.build();
}
HttpResponse<String> get_response = http_client.send(get_request, BodyHandlers.ofString());
JSONObject json = new JSONObject(((String)get_response.body()).substring(0,((String) get_response.body()).length())); JSONObject json = new JSONObject(get_response.body());
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(""))
return "Es ist ein Fehler aufgetreten!"; return "Es ist ein Fehler aufgetreten!";
else else
return weather + ": " + temperature + " °C"; return weather + " " + temperature + "°C";
} }
public String weather_forecast(String destination_zip){ public String[] weather_forecast(String destination_zip) {
String weather_day_1 = ""; String weather_day_1 = "";
String weather_day_2 = ""; String weather_day_2 = "";
String weather_day_3 = ""; String weather_day_3 = "";
String[] result = new String[3];
double temperature_day_1_1 = 1; double temperature_day_1_1 = 1;
double temperature_day_1_2 = 1; double temperature_day_1_2 = 1;
double temperature_day_1_3 = 1; double temperature_day_1_3 = 1;
double temperature_day_1_4 = 1; double temperature_day_1_4 = 1;
double temperature_day_1_5 = 1;
TreeSet<Double> temperature_day_1 = new TreeSet<>(); TreeSet<Double> temperature_day_1 = new TreeSet<>();
double temperature_day_1_high = 1; double temperature_day_1_high = 1;
@ -128,6 +402,7 @@ public class System {
double temperature_day_2_2 = 1; double temperature_day_2_2 = 1;
double temperature_day_2_3 = 1; double temperature_day_2_3 = 1;
double temperature_day_2_4 = 1; double temperature_day_2_4 = 1;
double temperature_day_2_5 = 1;
TreeSet<Double> temperature_day_2 = new TreeSet<>(); TreeSet<Double> temperature_day_2 = new TreeSet<>();
double temperature_day_2_high = 1; double temperature_day_2_high = 1;
@ -137,119 +412,279 @@ public class System {
double temperature_day_3_2 = 1; double temperature_day_3_2 = 1;
double temperature_day_3_3 = 1; double temperature_day_3_3 = 1;
double temperature_day_3_4 = 1; double temperature_day_3_4 = 1;
double temperature_day_3_5 = 1;
TreeSet<Double> temperature_day_3 = new TreeSet<>(); TreeSet<Double> temperature_day_3 = new TreeSet<>();
double temperature_day_3_high = 1; double temperature_day_3_high = 1;
double temperature_day_3_low = 1; double temperature_day_3_low = 1;
String day1date = "";
String day2date = "";
String day3date = "";
try{ try {
HttpClient http_client = HttpClient.newHttpClient(); HttpClient http_client = HttpClient.newHttpClient();
HttpRequest get_request;
HttpRequest get_request = HttpRequest.newBuilder() if(destination_zip.length()<5){
.uri(new URI("https://api.openweathermap.org/data/2.5/forecast?zip="+destination_zip+",de&appid="+api_key+"&units=metric&lang=de")) get_request = HttpRequest.newBuilder()
.GET() .uri(new URI("https://api.openweathermap.org/data/2.5/forecast?q=" + search(destination_zip).get(0).split(";")[1]
.build(); + ",de&appid=" + api_key + "&units=metric&lang=de"))
.GET()
.build();
}
else{
get_request = HttpRequest.newBuilder()
.uri(new URI("https://api.openweathermap.org/data/2.5/forecast?zip=" + destination_zip
+ ",de&appid=" + api_key + "&units=metric&lang=de"))
.GET()
.build();
}
HttpResponse get_response = http_client.send(get_request, BodyHandlers.ofString()); HttpResponse<String> get_response = http_client.send(get_request, BodyHandlers.ofString());
JSONObject json = new JSONObject(get_response.body());
int day1_1 = 0;
int day1_2 = 0;
int day1_3 = 0;
int day1_4 = 0;
int day1_5 = 0;
int day2_1 = 0;
int day2_2 = 0;
int day2_3 = 0;
int day2_4 = 0;
int day2_5 = 0;
int day3_1 = 0;
int day3_2 = 0;
int day3_3 = 0;
int day3_4 = 0;
int day3_5 = 0;
for (int i = 0; i < 40; i++) {
if (json.getJSONArray("list").getJSONObject(i).getString("dt_txt").split(" ")[1].startsWith("00")) {
day1_1 = i + 3; // 9 Uhr
day1_2 = day1_1 + 1; // 12 Uhr
day1_3 = day1_2 + 1; // 15 Uhr
day1_4 = day1_3 + 1; // 18 Uhr
day1_5 = day1_4 + 1; // 21 Uhr
break;
}
}
for (int i = day1_5; i < 40; i++) {
if (json.getJSONArray("list").getJSONObject(i).getString("dt_txt").split(" ")[1].startsWith("00")) {
day2_1 = i + 3; // 9 Uhr
day2_2 = day2_1 + 1; // 12 Uhr
day2_3 = day2_2 + 1; // 15 Uhr
day2_4 = day2_3 + 1; // 18 Uhr
day2_5 = day2_4 + 1; // 21 Uhr
break;
}
}
for (int i = day2_5 + 1; i < 40; i++) {
if (json.getJSONArray("list").getJSONObject(i).getString("dt_txt").split(" ")[1].startsWith("00")) {
day3_1 = i + 3; // 9 Uhr
day3_2 = day3_1 + 1; // 12 Uhr
day3_3 = day3_2 + 1; // 15 Uhr
day3_4 = day3_3 + 1; // 18 Uhr
day3_5 = day3_4 + 1; // 21 Uhr
break;
}
}
day1date = json.getJSONArray("list").getJSONObject(day1_1).getString("dt_txt").split(" ")[0];
day1date = day1date.split("-")[2] + "." + day1date.split("-")[1] + "." + day1date.split("-")[0];
day2date = json.getJSONArray("list").getJSONObject(day2_1).getString("dt_txt").split(" ")[0];
day2date = day2date.split("-")[2] + "." + day2date.split("-")[1] + "." + day2date.split("-")[0];
day3date = json.getJSONArray("list").getJSONObject(day3_1).getString("dt_txt").split(" ")[0];
day3date = day3date.split("-")[2] + "." + day3date.split("-")[1] + "." + day3date.split("-")[0];
weather_day_1 = json.getJSONArray("list").getJSONObject(day1_3).getJSONArray("weather").getJSONObject(0)
.getString("description");
weather_day_2 = json.getJSONArray("list").getJSONObject(day2_3).getJSONArray("weather").getJSONObject(0)
.getString("description");
weather_day_3 = json.getJSONArray("list").getJSONObject(day3_3).getJSONArray("weather").getJSONObject(0)
.getString("description");
temperature_day_1_1 = json.getJSONArray("list").getJSONObject(day1_1).getJSONObject("main")
.getDouble("temp");
temperature_day_1_2 = json.getJSONArray("list").getJSONObject(day1_2).getJSONObject("main")
.getDouble("temp");
temperature_day_1_3 = json.getJSONArray("list").getJSONObject(day1_3).getJSONObject("main")
.getDouble("temp");
temperature_day_1_4 = json.getJSONArray("list").getJSONObject(day1_4).getJSONObject("main")
.getDouble("temp");
temperature_day_1_5 = json.getJSONArray("list").getJSONObject(day1_5).getJSONObject("main")
.getDouble("temp");
temperature_day_2_1 = json.getJSONArray("list").getJSONObject(day2_1).getJSONObject("main")
.getDouble("temp");
temperature_day_2_2 = json.getJSONArray("list").getJSONObject(day2_2).getJSONObject("main")
.getDouble("temp");
temperature_day_2_3 = json.getJSONArray("list").getJSONObject(day2_3).getJSONObject("main")
.getDouble("temp");
temperature_day_2_4 = json.getJSONArray("list").getJSONObject(day2_4).getJSONObject("main")
.getDouble("temp");
temperature_day_2_5 = json.getJSONArray("list").getJSONObject(day2_5).getJSONObject("main")
.getDouble("temp");
temperature_day_3_1 = json.getJSONArray("list").getJSONObject(day3_1).getJSONObject("main")
.getDouble("temp");
temperature_day_3_2 = json.getJSONArray("list").getJSONObject(day3_2).getJSONObject("main")
.getDouble("temp");
temperature_day_3_3 = json.getJSONArray("list").getJSONObject(day3_3).getJSONObject("main")
.getDouble("temp");
temperature_day_3_4 = json.getJSONArray("list").getJSONObject(day3_4).getJSONObject("main")
.getDouble("temp");
temperature_day_3_5 = json.getJSONArray("list").getJSONObject(day3_5).getJSONObject("main")
.getDouble("temp");
} catch (Exception e) {
//
}
JSONObject json = new JSONObject(((String)get_response.body()).substring(0,((String) get_response.body()).length()));
weather_day_1 = json.getJSONArray("list").getJSONObject(11).getJSONArray("weather").getJSONObject(0).getString("description");
weather_day_2 = json.getJSONArray("list").getJSONObject(19).getJSONArray("weather").getJSONObject(0).getString("description");
weather_day_3 = json.getJSONArray("list").getJSONObject(27).getJSONArray("weather").getJSONObject(0).getString("description");
temperature_day_1_1 = json.getJSONArray("list").getJSONObject(8).getJSONObject("main").getDouble("temp");
temperature_day_1_2 = json.getJSONArray("list").getJSONObject(10).getJSONObject("main").getDouble("temp");
temperature_day_1_3 = json.getJSONArray("list").getJSONObject(12).getJSONObject("main").getDouble("temp");
temperature_day_1_4 = json.getJSONArray("list").getJSONObject(14).getJSONObject("main").getDouble("temp");
temperature_day_2_1 = json.getJSONArray("list").getJSONObject(16).getJSONObject("main").getDouble("temp");
temperature_day_2_2 = json.getJSONArray("list").getJSONObject(18).getJSONObject("main").getDouble("temp");
temperature_day_2_3 = json.getJSONArray("list").getJSONObject(20).getJSONObject("main").getDouble("temp");
temperature_day_2_4 = json.getJSONArray("list").getJSONObject(22).getJSONObject("main").getDouble("temp");
temperature_day_3_1 = json.getJSONArray("list").getJSONObject(24).getJSONObject("main").getDouble("temp");
temperature_day_3_2 = json.getJSONArray("list").getJSONObject(26).getJSONObject("main").getDouble("temp");
temperature_day_3_3 = json.getJSONArray("list").getJSONObject(28).getJSONObject("main").getDouble("temp");
temperature_day_3_4 = json.getJSONArray("list").getJSONObject(30).getJSONObject("main").getDouble("temp");
} catch (Exception e){}
temperature_day_1.add(temperature_day_1_1); temperature_day_1.add(temperature_day_1_1);
temperature_day_1.add(temperature_day_1_2); temperature_day_1.add(temperature_day_1_2);
temperature_day_1.add(temperature_day_1_3); temperature_day_1.add(temperature_day_1_3);
temperature_day_1.add(temperature_day_1_4); temperature_day_1.add(temperature_day_1_4);
temperature_day_1.add(temperature_day_1_5);
temperature_day_1_high = (double) temperature_day_1.toArray()[temperature_day_1.size()-1]; temperature_day_1_high = (double) temperature_day_1.toArray()[temperature_day_1.size() - 1];
temperature_day_1_low = (double) temperature_day_1.toArray()[0]; temperature_day_1_low = (double) temperature_day_1.toArray()[0];
temperature_day_2.add(temperature_day_2_1); temperature_day_2.add(temperature_day_2_1);
temperature_day_2.add(temperature_day_2_2); temperature_day_2.add(temperature_day_2_2);
temperature_day_2.add(temperature_day_2_3); temperature_day_2.add(temperature_day_2_3);
temperature_day_2.add(temperature_day_2_4); temperature_day_2.add(temperature_day_2_4);
temperature_day_2.add(temperature_day_2_5);
temperature_day_2_high = (double) temperature_day_2.toArray()[temperature_day_1.size()-1]; temperature_day_2_high = (double) temperature_day_2.toArray()[temperature_day_2.size() - 1];
temperature_day_2_low = (double) temperature_day_2.toArray()[0]; temperature_day_2_low = (double) temperature_day_2.toArray()[0];
temperature_day_3.add(temperature_day_3_1); temperature_day_3.add(temperature_day_3_1);
temperature_day_3.add(temperature_day_3_2); temperature_day_3.add(temperature_day_3_2);
temperature_day_3.add(temperature_day_3_3); temperature_day_3.add(temperature_day_3_3);
temperature_day_3.add(temperature_day_3_4); temperature_day_3.add(temperature_day_3_4);
temperature_day_3.add(temperature_day_3_5);
temperature_day_3_high = (double) temperature_day_3.toArray()[temperature_day_1.size()-1]; temperature_day_3_high = (double) temperature_day_3.toArray()[temperature_day_2.size() - 1];
temperature_day_3_low = (double) temperature_day_3.toArray()[0]; temperature_day_3_low = (double) temperature_day_3.toArray()[0];
if(weather_day_1.equals("")||weather_day_2.equals("")||weather_day_3.equals("")) if (weather_day_1.equals("") || weather_day_2.equals("") || weather_day_3.equals("")) {
return "Es ist ein Fehler aufgetreten!"; result[0] = "Es ist ein Fehler aufgetreten!";
else result[1] = "Es ist ein Fehler aufgetreten!";
return "Morgen: " + weather_day_1 + ": Minimum: " + temperature_day_1_low + " °C" + "; Maximum: " + temperature_day_1_high + " °C\n" result[2] = "Es ist ein Fehler aufgetreten!";
+ "Übermorgen: " + weather_day_2 + ": Minimum: " + temperature_day_2_low + " °C" + "; Maximum: " + temperature_day_2_high + " °C\n" } else {
+ "Überübermorgen: " + weather_day_3 + ": Minimum: " + temperature_day_3_low + " °C" + "; Maximum: " + temperature_day_3_high + " °C"; result[0] = day1date + ": " + weather_day_1 + " H: " + temperature_day_1_high + "°C" + " T: "
+ temperature_day_1_low + "°C";
result[1] = day2date + ": " + weather_day_2 + " H: " + temperature_day_2_high + "°C" + " T: "
+ temperature_day_2_low + "°C";
result[2] = day3date + ": " + weather_day_3 + " H: " + temperature_day_3_high + "°C" + " T: "
+ temperature_day_3_low + "°C";
}
return result;
} }
public String distance(String destination_zip){ public boolean all_distances() {
double lon1 = 1;
double lon2 = 1;
double lat1 = 1;
double lat2 = 1;
InputStream inputStream = Main.class.getResourceAsStream("/zip.csv"); double lon1 = -1;
double lon2 = -1;
double lat1 = -1;
double lat2 = -1;
double dLat;
double dLon;
double a;
double distance;
double result;
InputStream inputStream = System.class.getResourceAsStream("/zip.csv");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
line = line.replace("\"", ""); line = line.replace("\"", "");
if(line.split(";")[0].equals(destination_zip)){
lon2 = Double.parseDouble(line.split(";")[2]);
lat2 = Double.parseDouble(line.split(";")[3]);
}
if(line.split(";")[0].equals(""+current_user.getZip())){ if (line.split(";")[0].equals(current_user.getZip())) {
lon1 = Double.parseDouble(line.split(";")[2]); lon1 = Double.parseDouble(line.split(";")[2]);
lat1 = Double.parseDouble(line.split(";")[3]); lat1 = Double.parseDouble(line.split(";")[3]);
} }
} }
} catch (Exception e) {} } catch (Exception e) {
//
}
double dLat = lat2-lat1; InputStream inputStream2 = System.class.getResourceAsStream("/zip.csv");
double dLon = lon2-lon1;
double a = Math.pow(Math.sin(Math.toRadians(dLat/2.0)), 2) + Math.pow(Math.sin(Math.toRadians(dLon/2.0)), 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream2))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.replace("\"", "");
double distance = 6378.388 * 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0-a)); lon2 = Double.parseDouble(line.split(";")[2]);
lat2 = Double.parseDouble(line.split(";")[3]);
return "" + (distance * 1.25) + " km"; if (lon1 == -1 || lon2 == -1 || lat1 == -1 || lat2 == -1)
return false;
dLat = lat2 - lat1;
dLon = lon2 - lon1;
a = Math.pow(Math.sin(Math.toRadians(dLat / 2.0)), 2)
+ Math.pow(Math.sin(Math.toRadians(dLon / 2.0)), 2) * Math.cos(Math.toRadians(lat1))
* Math.cos(Math.toRadians(lat2));
distance = 6378.388 * 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a));
result = Math.round(distance * 1.25 * 100) / 100.0;
this.all_destinations.put(line.split(";")[0],
new Destination(line.split(";")[1], line.split(";")[0], result));
}
} catch (Exception e) {
//
}
return true;
} }
public String[] travel_time(String destination_zip){ public String distance(String destination_zip) {
return new String[1];
return "" + this.all_destinations.get(destination_zip).getDistance_from_user() + " km";
} }
public String calc_co2(String destination_zip){ public String[] travel_time(String destination_zip) {
return "";
String[] result = new String[2];
if (current_user.getCar_avg_kmh() == 0)
result[0] = "";
else
result[0] = "" + (Math.round(Double.parseDouble(distance(destination_zip).replace(" km", ""))
/ current_user.getCar_avg_kmh() * 100) / 100.0) + " h";
if (current_user.getBike_avg_kmh() == 0)
result[1] = "";
else
result[1] = "" + (Math.round(Double.parseDouble(distance(destination_zip).replace(" km", ""))
/ current_user.getBike_avg_kmh() * 100) / 100.0) + " h";
return result;
}
public String calc_l_consumption(String destination_zip) {
if (current_user.getCar_l_100km() == 0)
return "";
return "" + (Math.round(Double.parseDouble(distance(destination_zip).replace(" km", ""))
* current_user.getCar_l_100km() / 100.0 * 100) / 100.0) + " l";
} }
} }

View File

@ -5,11 +5,25 @@ public class User {
private String username = ""; private String username = "";
private String password = ""; private String password = "";
private String hometown = ""; private String hometown = "";
private int zip; private String zip = "";
private String car_name = ""; private String car_name = "";
private double car_co2_kmh; private double car_l_100km = 0;
private double car_avg_kmh; private double car_avg_kmh = 0;
private double bike_avg_kmh; private double bike_avg_kmh = 0;
public User(){}
public User(String username, String password, String hometown, String zip
, String car_name, double car_l_100km, double car_avg_kmh, double bike_avg_kmh){
this.username = username;
this.password = password;
this.hometown = hometown;
this.zip = zip;
this.car_name = car_name;
this.car_l_100km = car_l_100km;
this.car_avg_kmh = car_avg_kmh;
this.bike_avg_kmh = bike_avg_kmh;
}
public String getUsername() { public String getUsername() {
return username; return username;
@ -35,11 +49,11 @@ public class User {
this.hometown = hometown; this.hometown = hometown;
} }
public int getZip() { public String getZip() {
return zip; return zip;
} }
public void setZip(int zip) { public void setZip(String zip) {
this.zip = zip; this.zip = zip;
} }
@ -51,14 +65,14 @@ public class User {
this.car_name = car_name; this.car_name = car_name;
} }
public double getCar_co2_kmh() { public double getCar_l_100km() {
return car_co2_kmh; return car_l_100km;
} }
public void setCar_co2_kmh(double car_co2_kmh) { public void setCar_l_100km(double car_l_100km) {
this.car_co2_kmh = car_co2_kmh; this.car_l_100km = car_l_100km;
} }
public double getCar_avg_kmh() { public double getCar_avg_kmh() {
return car_avg_kmh; return car_avg_kmh;
} }
@ -74,4 +88,9 @@ public class User {
public void setBike_avg_kmh(double bike_avg_kmh) { public void setBike_avg_kmh(double bike_avg_kmh) {
this.bike_avg_kmh = bike_avg_kmh; this.bike_avg_kmh = bike_avg_kmh;
} }
public String toString(){
return this.username + ";" + System.encoding(this.password) + ";" + this.hometown + ";" + this.zip + ";" + this.car_name + ";"
+ this.car_l_100km + ";" + this.car_avg_kmh + ";" + this.bike_avg_kmh;
}
} }

View File

@ -1,7 +1,6 @@
package de.hs_mannheim.facade; package de.hs_mannheim.facade;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.TreeSet;
import de.hs_mannheim.domain.System; import de.hs_mannheim.domain.System;
@ -14,39 +13,54 @@ public class Application {
} }
public boolean sign_in_user(String username, String password){ public boolean sign_in_user(String username, String password){
return true; return running_system.sign_in_user(username, password);
} }
public boolean sign_up_user(String username, String password, String hometown, int zip, public boolean sign_up_user(String username, String password, String password_authentication, String hometown, String zip,
String car_name, double car_co2_km, double car_avg_kmh, double bike_avg_kmh){ String car_name, String car_co2_km, String car_avg_kmh, String bike_avg_kmh){
return true; 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(){
running_system.sign_out_user();
}
public boolean change_user_details(String username, String password, String hometown, int zip, public boolean change_user_details(String username, String password, String hometown, String zip,
String car_name, double car_co2_km, double car_avg_kmh, double bike_avg_kmh){ String car_name, String car_co2_km, String car_avg_kmh, String bike_avg_kmh){
return true; 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 new ArrayList<String>(); return running_system.search(hometown_or_zip);
} }
public ArrayList<String> random_destinations_car(){ public ArrayList<String> random_destinations_car(){
return new ArrayList<String>(); return running_system.random_destinations_car();
} }
public ArrayList<String> random_destinations_bike(){ public ArrayList<String> random_destinations_bike(){
return new ArrayList<String>(); return running_system.random_destinations_bike();
} }
public String[] destination_details(String destination_zip){ public String[] destination_details(String destination_zip){
return new String[1]; return running_system.destination_details(destination_zip);
} }
public String current_weather(){ public String current_weather(){
return ""; return running_system.current_weather();
} }
public String[] getDetails(){
return running_system.getDetails();
}
public String distance(String zip){
return running_system.distance(zip);
}
} }

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,2 @@
Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2
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 100.0 20.0

View File

@ -8,48 +8,169 @@ import java.util.ArrayList;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class SystemTest { public class SystemTest {
System current_system = new System("35a75437476f12302f72e55d368485db");
@Test @Test
public void weather_forecast(){ public void weather_forecast() {
System current_system = new System("35a75437476f12302f72e55d368485db"); current_system.sign_in_user("David", "123Esel");
assertNotEquals("Es ist ein Fehler aufgetreten!",current_system.weather_forecast("68161")); assertNotEquals("Es ist ein Fehler aufgetreten!", current_system.weather_forecast("68161")[0]);
} }
@Test @Test
public void current_weather(){ public void current_weather() {
System current_system = new System("35a75437476f12302f72e55d368485db"); current_system.sign_in_user("David", "123Esel");
current_system.set_current_user_zip("68161"); assertNotEquals("Es ist ein Fehler aufgetreten!", current_system.current_weather());
assertNotEquals("Es ist ein Fehler aufgetreten!",current_system.current_weather());
} }
@Test @Test
public void search(){ public void search() {
System current_system = new System("35a75437476f12302f72e55d368485db");
ArrayList<String> list = current_system.search("Mannheim"); ArrayList<String> list = current_system.search("Mannheim");
assertEquals("68159", list.get(0).split(";")[0]); assertEquals("68159", list.get(0).split(";")[0]);
assertEquals("68167", list.get(4).split(";")[0]); assertEquals("68167", list.get(4).split(";")[0]);
} }
@Test @Test
public void distance(){ public void distance() {
System current_system = new System("35a75437476f12302f72e55d368485db"); current_system.sign_in_user("David", "123Esel");
current_system.set_current_user_zip("68161"); assertEquals("88.46 km", current_system.distance("60306")); // Frankfurt
assertEquals("581.11 km", current_system.distance("20095")); // Hamburg
assertEquals("88.4596509227594 km", current_system.distance("60306")); // Frankfurt assertEquals("603.61 km", current_system.distance("10115")); // Berlin
assertEquals("581.1091061333296 km", current_system.distance("20095")); // Hamburg
assertEquals("603.6077163174941 km", current_system.distance("10115")); // Berlin
} }
} @Test
public void travel_time() {
current_system.sign_in_user("David", "123Esel");
assertEquals("0.88 h", current_system.travel_time("60306")[0]); // Frankfurt mit Auto
assertEquals("4.42 h", current_system.travel_time("60306")[1]); // Frankfurt mit Fahrrad
assertEquals("6.04 h", current_system.travel_time("10115")[0]); // Berlin mit Auto
assertEquals("30.18 h", current_system.travel_time("10115")[1]); // Berlin mit Fahrrad
}
@Test
public void calc_l_consumption() {
current_system.sign_in_user("David", "123Esel");
assertEquals("8.85 l", current_system.calc_l_consumption("60306")); // Kraftstoffverbrauch nach Frankfurt
assertEquals("58.11 l", current_system.calc_l_consumption("20095")); // Kraftstoffverbrauch nach Hamburg
assertEquals("60.36 l", current_system.calc_l_consumption("10115")); // Kraftstoffverbrauch nach Berlin
}
@Test
public void random_destinations() {
current_system.sign_in_user("David", "123Esel");
ArrayList<String> random_destination_car = current_system.random_destinations_car();
ArrayList<String> random_destination_bike = current_system.random_destinations_bike();
assertEquals(3, random_destination_car.size()); // random_destinations_car gibt genau 3 destinations zurück
assertEquals(3, random_destination_bike.size()); // random destinations_bike gibt genau 3 destinations zurück
// random_destinations_car gibt nur destinations mit mindestens 150 km
// Entfernung zurück
assertEquals(true, Double.parseDouble(
current_system.distance(random_destination_car.get(0).split(";")[0]).replace(" km", "")) > 150);
// random_destinations_bike gibt nur destinations mit maximal 100 km Entfernung
// zurück
assertEquals(true, Double.parseDouble(
current_system.distance(random_destination_bike.get(0).split(";")[0]).replace(" km", "")) < 100);
}
@Test
public void encoding() {
String test_password = "123Esel";
assertEquals("MTIzRXNlbA==", System.encoding(test_password));
}
@Test
public void decoding() {
String test_password = "MTIzRXNlbA==";
assertEquals("123Esel", System.decoding(test_password));
}
@Test
public void sign_in_user() {
assertEquals(true, current_system.sign_in_user("Daniel", "1401Daniel"));
assertEquals("Daniel", current_system.getDetails()[0]);
}
@Test
public void sign_out_user() {
assertEquals(true, current_system.sign_in_user("David", "123Esel"));
assertEquals("David", current_system.getDetails()[0]);
current_system.sign_out_user();
assertEquals("", current_system.getDetails()[0]);
}
@Test
public void sign_up_user() {
// Username darf nicht doppelt vorkommen!
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", "Penis69", "Mannheim", "68161", "AMG", "10",
"300", "20"));
// PLZ muss mit Stadt übereinstimmen
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", "123Esel", "Mannheim", "68305", "AMG", "10",
"300", "20"));
assertEquals("Lukas", current_system.getDetails()[0]);
current_system.sign_out_user();
assertEquals("", current_system.getDetails()[0]);
assertEquals(true, current_system.sign_in_user("Lukas", "123Esel"));
}
@Test
public void change_user_details() {
current_system.sign_in_user("David", "123Esel");
current_system.change_user_details("Enes", "123Esel", "Mannheim", "68161", "", "", "", "");
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:
* Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2
* David;MTIzRXNlbA==;Mannheim;68161;AMG;10.0;100.0;20.0
*/
}

View File

@ -0,0 +1,2 @@
Daniel;MTQwMURhbmllbA==;Mannheim;68305;BMW;1.5;50.4;40.2
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 100.0 20.0