diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 3b47d0f..d59c693 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -82,42 +82,52 @@ public class System { public ArrayList random_destinations_car(){ - ArrayList result = new ArrayList<>(); + ArrayList mem = new ArrayList<>(); InputStream inputStream = Main.class.getResourceAsStream("/zip.csv"); try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; - while ((line = reader.readLine()) != null && result.size()<3) { + while ((line = reader.readLine()) != null) { line = line.replace("\"", ""); if(Double.parseDouble(distance(line.split(";")[0]).replace(" km", "")) > 150) - result.add(line); + mem.add(line); } } catch (Exception e) {} + ArrayList result = new ArrayList<>(); + + for(int i = 0; i<3; i++) + result.add(mem.get((int) (Math.random()*mem.size()))); + return result; } public ArrayList random_destinations_bike(){ - ArrayList result = new ArrayList<>(); + ArrayList mem = new ArrayList<>(); InputStream inputStream = Main.class.getResourceAsStream("/zip.csv"); try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; - while ((line = reader.readLine()) != null && result.size()<3) { + while ((line = reader.readLine()) != null) { line = line.replace("\"", ""); if(Double.parseDouble(distance(line.split(";")[0]).replace(" km", "")) < 100) - result.add(line); + mem.add(line); } } catch (Exception e) {} + ArrayList result = new ArrayList<>(); + + for(int i = 0; i<3; i++) + result.add(mem.get((int) (Math.random()*mem.size()))); + return result; }