More Exception Handling

selims_dev_branch
Selim Eser 2024-06-11 15:13:37 +02:00
parent 0e4f7d35b7
commit 4a811935d2
2 changed files with 20 additions and 8 deletions

View File

@ -103,10 +103,22 @@ public class System {
public boolean sign_up_user(String username, String password, String hometown, String zipS, public boolean sign_up_user(String username, String password, String hometown, String zipS,
String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS){ String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS){
int zip = Integer.parseInt(zipS); int zip;
double car_l_100km = Double.parseDouble(car_l_100kmS); double car_l_100km;
double car_avg_kmh = Double.parseDouble(car_avg_kmhS); double car_avg_kmh;
double bike_avg_kmh = Double.parseDouble(bike_avg_kmhS); double bike_avg_kmh;
try{
zip = Integer.parseInt(zipS);
car_l_100km = Double.parseDouble(car_l_100kmS);
car_avg_kmh = Double.parseDouble(car_avg_kmhS);
bike_avg_kmh = Double.parseDouble(bike_avg_kmhS);
} catch (NumberFormatException n){
return false;
}
if(username.equals("")||password.equals("")||hometown.equals("")||zipS.equals(""))
return false;
for(User user: this.all_user) for(User user: this.all_user)
if(user.getUsername().equals(username)) if(user.getUsername().equals(username))

View File

@ -5,11 +5,11 @@ public class User {
private String username = ""; private String username = "";
private String password = ""; private String password = "";
private String hometown = ""; private String hometown = "";
private int zip; private int zip = 0;
private String car_name = ""; private String car_name = "";
private double car_l_100km; private double car_l_100km = 0;
private double car_avg_kmh; private double car_avg_kmh = 0;
private double bike_avg_kmh; private double bike_avg_kmh = 0;
public User(){} public User(){}