get_all_users method (complete but without encoding method)

get_all_user
Daniel Zdravkovic 2024-06-10 11:59:35 +02:00
parent 79b145e9f5
commit a41384a116
2 changed files with 44 additions and 5 deletions

View File

@ -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;
@ -40,8 +39,34 @@ public class System {
this.current_user.setBike_avg_kmh(bike_avg_kmh);
}
public HashSet<User> get_all_user(){
return new HashSet<User>();
public void encoding(String string){
}
public HashSet<User> get_all_user() throws FileNotFoundException, IOException{
HashSet<User> 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){

View File

@ -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;
}