Added a luancher file

Chaged the jvm entry point to the launcher
added some slight redundancy in case of missing folders
This commit is contained in:
2025-04-24 09:18:20 +02:00
parent 86b505b4e3
commit 86f67b07c9
4 changed files with 72 additions and 5 deletions

View File

@@ -22,6 +22,6 @@ test {
jar{
manifest {
attributes 'Main-class': 'me.zacharias.bank.Main'
attributes 'Main-class': 'me.zacharias.bank.Launcher'
}
}

View File

@@ -0,0 +1,63 @@
package me.zacharias.bank;
import me.zacharias.bank.app.Main;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.UUID;
public class Launcher {
public static void main(String[] args) {
ArrayList<String> argsList = new ArrayList<>();
for(String arg : args) {
argsList.add(arg);
}
ArrayList<String> newUsers = new ArrayList<>();
for(int i = 0; i < argsList.size(); i++) {
String arg = argsList.get(i);
if(arg.equals("--new") || arg.equals("-n")) {
if(argsList.size() < i+2) {
System.out.println("Not enough arguments");
System.exit(1);
}
String name = argsList.get(i+1);
newUsers.add(name);
}
if(arg.equals("--help") || arg.equals("-h")) {
System.out.println("""
Usage: java -jar Bank.jar [--new <name>] [--help]
Options:
-n --new <name> Create a new user with the given name
-h --help Show this help message
""");
System.exit(0);
}
}
ArrayList<User> users = new ArrayList<>();
for (String name : newUsers) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter password for " + name + ": ");
String password = reader.readLine();
User user = new User(name);
Account a = user.createAccount("Konto");
a.DepositTransaction(100, "Welcome to the bank", UUID.fromString("00000000-0000-0000-0000-000000000000"));
user.write();
users.add(user);
}catch (Exception e) {
System.out.println("Error on user "+name+": " + e.getMessage());
}
}
Main.main(args);
}
}

View File

@@ -21,16 +21,16 @@ public class User {
accounts = new ArrayList<>();
}
public UUID createAccount(String name) {
public Account createAccount(String name) {
Account account = new BankAccount(name);
accounts.add(account);
return account.getId();
return account;
}
public UUID createSavingsAccount(String name) {
public Account createSavingsAccount(String name) {
Account account = new SavingsAccount(name);
accounts.add(account);
return account.getId();
return account;
}
public Account getAccount(String name) {

View File

@@ -142,6 +142,10 @@ public class Utils {
{
file.delete();
}
if(file.getParentFile() != null && !file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
try {
file.createNewFile();