From e756deaa3038ce6e49f09e4d8f71fc0382642fa6 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 14:26:05 +0100 Subject: [PATCH] Added a birthday variable to the signup function --- src/main/java/SignUp.java | 36 ++++++++++++++++++++++++------------ user.json | 1 + 2 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 user.json diff --git a/src/main/java/SignUp.java b/src/main/java/SignUp.java index ca443dd..fe9ada6 100644 --- a/src/main/java/SignUp.java +++ b/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"); diff --git a/user.json b/user.json new file mode 100644 index 0000000..b8726e5 --- /dev/null +++ b/user.json @@ -0,0 +1 @@ +{"userName":"Test User","password":"TestPasswort","birthday":"01.01.1900"} \ No newline at end of file