Browse Source

Added a birthday variable to the signup function

remotes/origin/feature/client/make-input-field-buttons-interactive
Richard Schmidt 11 months ago
parent
commit
e756deaa30
  1. 36
      src/main/java/SignUp.java
  2. 1
      user.json

36
src/main/java/SignUp.java

@ -3,22 +3,24 @@ import java.io.FileWriter;
import java.io.IOException;
public class SignUp {
private String name;
private String userName;
private String password;
private String birthday;
// Constructor
public SignUp(String name, String password) {
this.name = name;
public SignUp(String name, String password, String birthday) {
this.userName = name;
this.password = password;
this.birthday = birthday;
}
// Getters and Setters
public String getName() {
return name;
public String getUserName() {
return userName;
}
public void setName(String name) {
this.name = name;
public void setName(String userName) {
this.userName = userName;
}
public String getPassword() {
@ -28,10 +30,18 @@ public class SignUp {
public void setPassword(String password) {
this.password = password;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
// Function to create user with validation
public static SignUp createUser(String name, String password) {
if (name == null || name.isEmpty()) {
public static SignUp createUser(String userName, String password, String birthday) {
if (userName == null || userName.isEmpty()) {
throw new IllegalArgumentException("Username cannot be empty");
}
if (password == null || password.isEmpty()) {
@ -39,7 +49,7 @@ public class SignUp {
}
if (password.length() < 6) {
throw new IllegalArgumentException("Password must be at least 6 characters long");
} return new SignUp(name, password);
} return new SignUp(userName, password, birthday);
}
// Function to save to JSON file, replace with database call later
@ -56,11 +66,13 @@ public class SignUp {
public static void main(String[] args) {
try {
// Example usage
SignUp user = createUser("Test User", "TestPasswort");
SignUp user = createUser("Test User", "TestPasswort", "01.01.1900");
// Example of accessing properties
System.out.println("User Name: " + user.getName());
System.out.println("User Name: " + user.getUserName());
System.out.println("User Password: " + user.getPassword());
System.out.println("User Birthday: " + user.getBirthday());
// Save user information to a JSON file
user.saveToJsonFile("user.json");

1
user.json

@ -0,0 +1 @@
{"userName":"Test User","password":"TestPasswort","birthday":"01.01.1900"}
Loading…
Cancel
Save