Made so each Transaction handler in the Account class to return the transaction object. Updated the Utils class to handle the transactions que reading and writing. Added org.json to aid in trnsaction que handling. made so accounts can update there balance and transactions from the transaction que. Added a tranfer window to handle the transfer of money between acounts.
100 lines
2.7 KiB
Java
100 lines
2.7 KiB
Java
package me.zacharias.bank;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
import java.io.Console;
|
|
import java.io.File;
|
|
import java.util.UUID;
|
|
|
|
import static me.zacharias.bank.Utils.*;
|
|
|
|
public class Main {
|
|
User user;
|
|
|
|
public static void main(String[] args) {
|
|
{
|
|
String username = "theo";
|
|
String user = SHA256(username);
|
|
File userFile = new File("./users/" + user + ".json");
|
|
|
|
if (!userFile.exists()) {
|
|
|
|
User u = new User(username);
|
|
u.createAccount("Konto");
|
|
Account a = u.getAccount("Konto");
|
|
a.DepositTransaction(100, "Deposit", UUID.randomUUID());
|
|
|
|
String json = gson.toJson(u);
|
|
try {
|
|
WriteFile(userFile, Encrypt(json, "pass"));
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
{
|
|
String username = "user";
|
|
String user = SHA256(username);
|
|
File userFile = new File("./users/" + user + ".json");
|
|
|
|
if (!userFile.exists()) {
|
|
|
|
User u = new User(username);
|
|
u.createAccount("Konto");
|
|
Account a = u.getAccount("Konto");
|
|
a.DepositTransaction(100, "Deposit", UUID.randomUUID());
|
|
|
|
String json = gson.toJson(u);
|
|
try {
|
|
WriteFile(userFile, Encrypt(json, "pass"));
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
new Main();
|
|
}
|
|
|
|
public Main() {
|
|
|
|
Console console = System.console();
|
|
|
|
if(console == null) {
|
|
System.out.println("No console.");
|
|
//return;
|
|
}
|
|
|
|
String name = "theo";//console.readLine("Enter your name: ");
|
|
|
|
String userHash = SHA256(name);
|
|
|
|
File userFile = new File("./users/" + userHash + ".json");
|
|
|
|
if(!userFile.exists()) {
|
|
System.out.println("User does not exist");
|
|
return;
|
|
}
|
|
|
|
String password = "pass";//new String(console.readPassword("Enter your password: "));
|
|
|
|
String userData;
|
|
|
|
try {
|
|
userData = Decrypt(ReadFile(userFile), password);
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
|
|
System.out.println(userData);
|
|
|
|
user = gson.fromJson(userData, User.class);
|
|
|
|
Account a = user.getAccount("Konto");
|
|
System.out.println(a.getClass().getSimpleName());
|
|
System.out.println(a.getBalance());
|
|
}
|
|
}
|