Registrierung und Einlpggen Methoden
parent
937c75bc44
commit
e9478289c5
|
@ -1,5 +1,11 @@
|
|||
package domain;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class User {
|
||||
|
||||
private String username;
|
||||
|
@ -19,16 +25,97 @@ public class User {
|
|||
this.durchschnittsgeschwindigkeitFahrrad = durchschnittsgeschwindigkeitFahrrad;
|
||||
}
|
||||
|
||||
public void registrieren() {
|
||||
// Implementierung der Registrierung
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void einloggen() {
|
||||
// Implementierung des Logins
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public Ort getHeimatstandort() {
|
||||
return heimatstandort;
|
||||
}
|
||||
|
||||
public void setHeimatstandort(Ort heimatstandort) {
|
||||
this.heimatstandort = heimatstandort;
|
||||
}
|
||||
|
||||
public Auto getAuto() {
|
||||
return auto;
|
||||
}
|
||||
|
||||
public void setAuto(Auto auto) {
|
||||
this.auto = auto;
|
||||
}
|
||||
|
||||
public double getDurchschnittsgeschwindigkeitPKW() {
|
||||
return durchschnittsgeschwindigkeitPKW;
|
||||
}
|
||||
|
||||
public void setDurchschnittsgeschwindigkeitPKW(double durchschnittsgeschwindigkeitPKW) {
|
||||
this.durchschnittsgeschwindigkeitPKW = durchschnittsgeschwindigkeitPKW;
|
||||
}
|
||||
|
||||
public double getDurchschnittsgeschwindigkeitFahrrad() {
|
||||
return durchschnittsgeschwindigkeitFahrrad;
|
||||
}
|
||||
|
||||
public void setDurchschnittsgeschwindigkeitFahrrad(double durchschnittsgeschwindigkeitFahrrad) {
|
||||
this.durchschnittsgeschwindigkeitFahrrad = durchschnittsgeschwindigkeitFahrrad;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void registrieren() {
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter("users.txt", true))) {
|
||||
writer.println(username + "," + password + "," + heimatstandort.getPLZ() + "," + heimatstandort.getOrtName() + ","
|
||||
+ auto.getName() + "," + auto.getCO2AusstossProKm() + "," + durchschnittsgeschwindigkeitPKW + ","
|
||||
+ durchschnittsgeschwindigkeitFahrrad);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean einloggen() {
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader("users.txt"))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] parts = line.split(",");
|
||||
if (parts[0].equals(username) && parts[1].equals(password)) {
|
||||
// Benutzerdaten laden
|
||||
this.heimatstandort = new Ort(parts[2], parts[3]);
|
||||
this.auto = new Auto(parts[4], Double.parseDouble(parts[5]));
|
||||
this.durchschnittsgeschwindigkeitPKW = Double.parseDouble(parts[6]);
|
||||
this.durchschnittsgeschwindigkeitFahrrad = Double.parseDouble(parts[7]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void zeigeWetterHeimatstandort() {
|
||||
// Implementierung der Wetteranzeige
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue