From 1aed134131fdb2341b38f2eee28f850af791295a Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Sun, 9 Jun 2024 21:15:39 +0200 Subject: [PATCH] Corrected the method logic --- .../java/de/hs_mannheim/domain/System.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) 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; }