From a41384a1165ef1022366e492fbe9178e4ef42222 Mon Sep 17 00:00:00 2001 From: Daniel Zdravkovic <3012893@stud.hs-mannheim.de> Date: Mon, 10 Jun 2024 11:59:35 +0200 Subject: [PATCH] get_all_users method (complete but without encoding method) --- .../java/de/hs_mannheim/domain/System.java | 35 ++++++++++++++++--- src/main/java/de/hs_mannheim/domain/User.java | 14 ++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index cf8c246..b91c89e 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -1,14 +1,13 @@ package de.hs_mannheim.domain; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; +import java.io.*; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.TreeSet; @@ -39,9 +38,35 @@ public class System { public void set_current_user_bike_avg_kmh(double bike_avg_kmh){ this.current_user.setBike_avg_kmh(bike_avg_kmh); } + + public void encoding(String string){ + + } - public HashSet get_all_user(){ - return new HashSet(); + public HashSet get_all_user() throws FileNotFoundException, IOException{ + HashSet all_users = new HashSet<>(); + File file = new File("user_information.csv"); + String[] fileString = new String[8]; + + if(file.exists() && file.isFile()){ + FileReader fileReader = new FileReader(file); + BufferedReader bufferedReader = new BufferedReader(fileReader); + String path; + + while((path = bufferedReader.readLine()) != null){ + fileString = path.split(";"); + fileString = (String[]) Arrays.stream(fileString) + .map(string -> string.substring(0, string.length()-1)) + .toArray(); + encoding(fileString[1]); + all_users.add(new User(fileString[0], fileString[1], fileString[2], + Integer.parseInt(fileString[3]), fileString[4], + Double.parseDouble(fileString[5]), + Double.parseDouble(fileString[6]), + Double.parseDouble(fileString[7]))); + } + } + return all_users; } public boolean sign_in_user(String username, String password){ diff --git a/src/main/java/de/hs_mannheim/domain/User.java b/src/main/java/de/hs_mannheim/domain/User.java index 54eacac..cd9b6f9 100644 --- a/src/main/java/de/hs_mannheim/domain/User.java +++ b/src/main/java/de/hs_mannheim/domain/User.java @@ -11,6 +11,20 @@ public class User { private double car_avg_kmh; private double bike_avg_kmh; + public User(){} + + public User(String username, String password, String hometown, int 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() { return username; }