Finished implementing
parent
531407dcf7
commit
d366227c52
|
@ -2,13 +2,24 @@ package de.hs_mannheim.domain;
|
||||||
|
|
||||||
public class Destination {
|
public class Destination {
|
||||||
|
|
||||||
|
private String town;
|
||||||
private String zip;
|
private String zip;
|
||||||
private double distance_from_user;
|
private double distance_from_user;
|
||||||
|
|
||||||
public Destination(String zip, double distance_from_user) {
|
public Destination(String town,String zip, double distance_from_user) {
|
||||||
|
this.town = town;
|
||||||
this.zip = zip;
|
this.zip = zip;
|
||||||
this.distance_from_user = distance_from_user;
|
this.distance_from_user = distance_from_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTown() {
|
||||||
|
return town;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTown(String town) {
|
||||||
|
this.town = town;
|
||||||
|
}
|
||||||
|
|
||||||
public String getZip() {
|
public String getZip() {
|
||||||
return zip;
|
return zip;
|
||||||
}
|
}
|
||||||
|
@ -22,5 +33,4 @@ public class Destination {
|
||||||
this.distance_from_user = distance_from_user;
|
this.distance_from_user = distance_from_user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ public class System {
|
||||||
private ArrayList<User> all_user = new ArrayList<>();
|
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>();
|
private HashMap<String, Destination> all_destinations = new HashMap<String, Destination>();
|
||||||
private ArrayList<String> distances = new ArrayList<>();
|
|
||||||
|
|
||||||
public System(String api_key) {
|
public System(String api_key) {
|
||||||
this.api_key = api_key;
|
this.api_key = api_key;
|
||||||
|
@ -103,6 +102,8 @@ public class System {
|
||||||
current_user = new User(user.getUsername(), user.getPassword(),
|
current_user = new User(user.getUsername(), user.getPassword(),
|
||||||
user.getHometown(), user.getZip(), user.getCar_name(),
|
user.getHometown(), user.getZip(), user.getCar_name(),
|
||||||
user.getCar_l_100km(), user.getCar_avg_kmh(), user.getBike_avg_kmh());
|
user.getCar_l_100km(), user.getCar_avg_kmh(), user.getBike_avg_kmh());
|
||||||
|
|
||||||
|
all_distances();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -150,6 +151,7 @@ public class System {
|
||||||
write_to_file(all_user_toString(), "src/main/resources/user_data.csv");
|
write_to_file(all_user_toString(), "src/main/resources/user_data.csv");
|
||||||
write_to_file(all_user_toString(), "src/test/resources/user_data.csv");
|
write_to_file(all_user_toString(), "src/test/resources/user_data.csv");
|
||||||
|
|
||||||
|
all_distances();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,6 +203,7 @@ public class System {
|
||||||
write_to_file(all_user_toString(), "src/main/resources/user_data.csv");
|
write_to_file(all_user_toString(), "src/main/resources/user_data.csv");
|
||||||
write_to_file(all_user_toString(), "src/test/resources/user_data.csv");
|
write_to_file(all_user_toString(), "src/test/resources/user_data.csv");
|
||||||
|
|
||||||
|
all_distances();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -216,8 +219,6 @@ public class System {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sign_out_user() {
|
public void sign_out_user() {
|
||||||
this.distances = new ArrayList<>();
|
|
||||||
|
|
||||||
current_user = new User();
|
current_user = new User();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,33 +251,37 @@ public class System {
|
||||||
|
|
||||||
public ArrayList<String> random_destinations_car() {
|
public ArrayList<String> random_destinations_car() {
|
||||||
|
|
||||||
ArrayList<String> mem = new ArrayList<>();
|
ArrayList<Destination> mem = new ArrayList<>();
|
||||||
ArrayList<String> result = new ArrayList<>();
|
ArrayList<String> result = new ArrayList<>();
|
||||||
|
int random = 0;
|
||||||
|
|
||||||
for (int i = 0; i < this.distances.size(); i++) {
|
for(Destination destination: this.all_destinations.values()){
|
||||||
if (Double.parseDouble(this.distances.get(i).split(";")[2]) > 150)
|
if(destination.getDistance_from_user()>150)
|
||||||
mem.add(this.distances.get(i));
|
mem.add(destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++){
|
||||||
result.add(mem.get((int) (Math.random() * mem.size())));
|
random = (int) (Math.random() * mem.size());
|
||||||
|
result.add(mem.get(random).getZip() + ";" + mem.get(random).getTown());
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> random_destinations_bike() {
|
public ArrayList<String> random_destinations_bike() {
|
||||||
|
|
||||||
ArrayList<String> mem = new ArrayList<>();
|
ArrayList<Destination> mem = new ArrayList<>();
|
||||||
ArrayList<String> result = new ArrayList<>();
|
ArrayList<String> result = new ArrayList<>();
|
||||||
|
int random = 0;
|
||||||
|
|
||||||
for (int i = 0; i < this.distances.size(); i++) {
|
for(Destination destination: this.all_destinations.values()){
|
||||||
if (Double.parseDouble(this.distances.get(i).split(";")[2]) < 100)
|
if(destination.getDistance_from_user()<100)
|
||||||
mem.add(this.distances.get(i));
|
mem.add(destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++){
|
||||||
result.add(mem.get((int) (Math.random() * mem.size())));
|
random = (int) (Math.random() * mem.size());
|
||||||
|
result.add(mem.get(random).getZip() + ";" + mem.get(random).getTown());
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,7 +443,7 @@ public class System {
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
line = line.replace("\"", "");
|
line = line.replace("\"", "");
|
||||||
|
|
||||||
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]);
|
||||||
}
|
}
|
||||||
|
@ -466,7 +471,7 @@ public class System {
|
||||||
|
|
||||||
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(";")[0], result));
|
this.all_destinations.put(line.split(";")[0],new Destination(line.split(";")[1],line.split(";")[0], result));
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -477,7 +482,7 @@ public class System {
|
||||||
|
|
||||||
public String distance(String destination_zip){
|
public String distance(String destination_zip){
|
||||||
|
|
||||||
return "" + this.all_destinations.get(destination_zip) + " km";
|
return "" + this.all_destinations.get(destination_zip).getDistance_from_user() + " km";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,12 +490,6 @@ public class System {
|
||||||
|
|
||||||
String[] result = new String[2];
|
String[] result = new String[2];
|
||||||
|
|
||||||
if (distance(destination_zip).equals("Es ist ein Fehler aufgetreten!")) {
|
|
||||||
result[0] = "Es ist ein Fehler aufgetreten!";
|
|
||||||
result[1] = "Es ist ein Fehler aufgetreten!";
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
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";
|
||||||
|
|
||||||
|
@ -499,9 +498,6 @@ public class System {
|
||||||
|
|
||||||
public String calc_l_consumption(String destination_zip) {
|
public String calc_l_consumption(String destination_zip) {
|
||||||
|
|
||||||
if (distance(destination_zip).equals("Es ist ein Fehler aufgetreten!"))
|
|
||||||
return "Es ist ein Fehler aufgetreten!";
|
|
||||||
|
|
||||||
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";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue