Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
103 changes: 103 additions & 0 deletions src/main/java/com/booleanuk/core/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.booleanuk.core;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

public abstract class Account {
private UUID id;
private UUID CustomerUUID;
private List<Transaction> transactions;
private AccountType accountType;

public Account(UUID CustomerUUID, AccountType accountType) {
this.id = UUID.randomUUID();
this.CustomerUUID = CustomerUUID;
this.transactions = new ArrayList<Transaction>();
this.accountType = accountType;
}

public void addTransaction(double amount) {
this.transactions.add(new Transaction(amount));
}

public double calculateBalance() {
return transactions.stream().mapToDouble(Transaction::getAmount).sum();
}

public UUID getId() {
return id;
}

public void setId(UUID id) {
this.id = id;
}

public UUID getCustomerUUID() {
return CustomerUUID;
}

public void setCustomerUUID(UUID customerUUID) {
CustomerUUID = customerUUID;
}

public List<Transaction> getTransactions() {
return transactions;
}

public void setTransactions(List<Transaction> transactions) {
this.transactions = transactions;
}

public AccountType getAccountType() {
return accountType;
}

public void setAccountType(AccountType accountType) {
this.accountType = accountType;
}

@Override
public String toString() {
return "Account{" +
"id=" + id +
", CustomerUUID=" + CustomerUUID +
", transactions=" + transactions +
", accountType=" + accountType +
'}';
}

public void printAccountStatement() {

final String rowFmt = "%-15s||%15s||%15s||%15s%n";
System.out.printf(rowFmt,"date", "credit", "debit", "balance");

// Date Innskudd Utrekk Balanse
double balance = 0;

for (Transaction transaction : transactions) {
String transactionDate = transaction.getDate().toString();
double amount = transaction.getAmount();
String credit = "";
String debit = "";

if(amount <= 0) {
debit = Double.toString(
Math.abs(amount));
}
else{
credit = Double.toString(
amount);
}

balance = balance + amount;

System.out.printf(rowFmt,transactionDate, credit, debit, balance);

}
}
}

6 changes: 6 additions & 0 deletions src/main/java/com/booleanuk/core/AccountType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.booleanuk.core;

public enum AccountType {
CURRENT,
SAVINGS
}
10 changes: 10 additions & 0 deletions src/main/java/com/booleanuk/core/BankManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.List;

public class BankManager {
private String name;
private ArrayList<String> branchUUIDs;

}
37 changes: 37 additions & 0 deletions src/main/java/com/booleanuk/core/Branch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class Branch {
private List<Account> accounts;
private UUID id;
private String name;

public Branch(String name) {
this.name = name;
this.accounts = new ArrayList<Account>();
this.id = UUID.randomUUID();
}

public void createSavingsAccountForUser(UUID customerId) {
this.accounts.add(new SavingsAccount(customerId));
}

public void createCurrentAccountForUser(UUID customerId) {
this.accounts.add(new CurrentAccount(customerId));
}

public List<Account> getAccountsForCustomerID(UUID customerId) {
return this.accounts.stream()
.filter(account -> account.getCustomerUUID().equals(customerId))
.toList();
}

public List<Account> getAccountsForAccountID(UUID accountID) {
return this.accounts.stream()
.filter(account -> account.getId().equals(accountID))
.toList();
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/booleanuk/core/CurrentAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.booleanuk.core;

import java.util.UUID;
import com.booleanuk.core.AccountType;

public class CurrentAccount extends Account {
private static final AccountType accountType = AccountType.CURRENT;
private double overdraftLimit;
private boolean overdraftApproved;

public CurrentAccount(UUID CustomerUUID) {
super(CustomerUUID, accountType);
this.overdraftLimit = 0;
this.overdraftApproved = false;
}

public double getOverdraftLimit() {
return overdraftLimit;
}

public void setOverdraftLimit(double overdraftLimit) {
this.overdraftApproved = false;
this.overdraftLimit = overdraftLimit;
}

public boolean isOverdraftApproved() {
return overdraftApproved;
}

public void setOverdraftApproved(boolean overdraftApproved) {
this.overdraftApproved = overdraftApproved;
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/booleanuk/core/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.booleanuk.core;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class Customer extends User {

private List<UUID> accountUUIDs;
public Customer(String name) {
super(name);
this.accountUUIDs = new ArrayList<UUID>();
}

public List<UUID> getAccountUUIDs() {
return accountUUIDs;
}

public void addAccount(UUID accountUUID) {
this.accountUUIDs.add(accountUUID);
}
}
13 changes: 13 additions & 0 deletions src/main/java/com/booleanuk/core/SavingsAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.booleanuk.core;

import java.util.UUID;

public class SavingsAccount extends Account {
private float interestRate;
private static final AccountType accountType = AccountType.SAVINGS;

public SavingsAccount(UUID CustomerUUID) {
super(CustomerUUID, accountType);
this.interestRate = 0;
}
}
40 changes: 40 additions & 0 deletions src/main/java/com/booleanuk/core/Transaction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.booleanuk.core;

import java.time.LocalDate;
import java.util.UUID;

public class Transaction {
private double amount;
private LocalDate date;
private UUID id;

public Transaction(double amount) {
this.date = LocalDate.now();
this.amount = amount;
this.id = UUID.randomUUID();
}

public double getAmount() {
return amount;
}

public void setAmount(float amount) {
this.amount = amount;
}

public LocalDate getDate() {
return date;
}

public void setDate(LocalDate date) {
this.date = date;
}

public UUID getId() {
return id;
}

public void setId(UUID id) {
this.id = id;
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/booleanuk/core/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.booleanuk.core;

import java.util.UUID;

public abstract class User {
private UUID uuid;
private String name;

public User(String name) {
this.uuid = java.util.UUID.randomUUID();
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public UUID getUUID() {
return uuid;
}

public void setUUID(UUID uuid) {
this.uuid = uuid;
}
}
Empty file.
39 changes: 39 additions & 0 deletions src/test/java/com/booleanuk/core/AccountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.UUID;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AccountTest {

@Test
public void addTransaction() {
Branch testBranch = new Branch("oslo");
User testCustomer = new Customer("Trond Giske");
UUID testUserUUID = testCustomer.getUUID();

testBranch.createCurrentAccountForUser(testUserUUID);
Account testAccount = testBranch.getAccountsForCustomerID(testUserUUID).getFirst();
testAccount.addTransaction(1000.99);
Transaction testTransaction = testAccount.getTransactions().getFirst();

assertEquals(1000.99, testTransaction.getAmount());
}

@Test
public void calculateBalance() {
Branch testBranch = new Branch("oslo");
User testCustomer = new Customer("Trond Giske");
UUID testUserUUID = testCustomer.getUUID();

testBranch.createCurrentAccountForUser(testUserUUID);
Account testAccount = testBranch.getAccountsForCustomerID(testUserUUID).getFirst();
testAccount.addTransaction(1000.99);
testAccount.addTransaction(1000.99);

assertEquals(2001.98, testAccount.calculateBalance());
}
}
13 changes: 13 additions & 0 deletions src/test/java/com/booleanuk/core/BankManagerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.booleanuk.core;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

public class BankManagerTest {
@Test
public void testBankManager() {
// Nothing to test here except getters and setters
assertTrue(true);
}
}
Loading
Loading