Skip to content
Closed
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
15 changes: 15 additions & 0 deletions src/main/java/com/booleanuk/core/Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.booleanuk.core;

public interface Account {


BankStatement getBankstatement();
boolean deposit(double amount);
boolean withdraw(double amount);
double getBalance();
Enum<Branches> getBranch();
void setBranch(Enum<Branches> newBranch);
boolean requestOverdraft(double amount);


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

public enum AccountOperation {
DEPOSIT,
WITHDRAW,
}
38 changes: 38 additions & 0 deletions src/main/java/com/booleanuk/core/BankStatement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.booleanuk.core;


import java.util.ArrayList;
import java.util.List;
import static com.booleanuk.core.AccountOperation.*;

public class BankStatement {

private List<Transaction> transactions = new ArrayList<>();

public BankStatement(){

}

public void printStatement(){

String x = String.format("%-15s || %-15s || %-15s || %s" , "date", "credit", "debit", "balance" );
System.out.println(x);

for (Transaction t : transactions){
if(t.getType()==DEPOSIT)
System.out.printf("%-15s || %-15s || %-15s || %s%n", t.getDate(), 0 , t.getAmount(), t.getBalance() );
else
System.out.printf("%-15s || %-15s || %-15s || %s%n", t.getDate(), t.getAmount() ,0 , t.getBalance() );

}
}


public boolean add(Transaction t){
return transactions.add(t);
}

public List<Transaction> getTransactions() {
return transactions;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/booleanuk/core/Branches.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.booleanuk.core;

public enum Branches {

OSLO,
TRONDHEIM,
BERGEN,


}
73 changes: 73 additions & 0 deletions src/main/java/com/booleanuk/core/CurrentAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.booleanuk.core;
import static com.booleanuk.core.AccountOperation.*;
import static com.booleanuk.core.Branches.*;

public class CurrentAccount implements Account{

private double balance;
private Enum<Branches> branch;
private final BankStatement bankStatement = new BankStatement();
private final double OVERDRAFTLIMIT = -3000;

public CurrentAccount(){
balance = calculateBalance();
this.branch = OSLO;

}

@Override
public BankStatement getBankstatement() {
return this.bankStatement;
}

@Override
public boolean deposit(double amount) {
if(amount < 0 ) return false;
Transaction t = new Transaction(amount,this.balance+amount,DEPOSIT);
this.bankStatement.add(t);
this.balance+=amount;
return true;
}

@Override
public boolean withdraw(double amount) {
if(amount < 0 || this.balance-amount < 0 ) return false;
Transaction t = new Transaction(amount,this.balance - amount, WITHDRAW);
bankStatement.add(t);
this.balance-=amount;

return true;
}

@Override
public double getBalance() {
return this.balance;
}

@Override
public Enum<Branches> getBranch() {
return this.branch;
}

@Override
public void setBranch(Enum<Branches> newBranch) {
this.branch = newBranch;
}

private double calculateBalance(){

if(bankStatement.getTransactions().isEmpty())
return 0;

double sum = 0;
for (Transaction t : bankStatement.getTransactions())
sum += t.getAmount();

return sum;

}

public boolean requestOverdraft(double amount){
return this.balance-amount < OVERDRAFTLIMIT;
}
}
76 changes: 76 additions & 0 deletions src/main/java/com/booleanuk/core/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.booleanuk.core;


public class Customer {

private Account currentAccount;
private Account savingsAccount;

public Customer(){

}

public Account getCurrentAccount() {
return currentAccount;
}

public Account getSavingsAccount() {
return savingsAccount;
}

public boolean createCurrentAccount(){
if(currentAccount != null) return false;

currentAccount = new CurrentAccount();
return true;

}

public boolean createSavingsAccount(){

if(savingsAccount != null) return false;

savingsAccount = new SavingsAccount();

return true;
}

public boolean deposit(Account ac, double amount){
if(ac == null || amount < 0)
return false;

ac.deposit(amount);
return true;

}

public boolean withdraw(Account ac, double amount){
if(ac == null || amount < 0)
return false;

ac.deposit(amount);
return true;
}

public BankStatement getBankStatement(Account ac) {
return ac.getBankstatement();
}

public boolean changeAccountBranch(Account ac, Enum<Branches> branch){
if(ac==null)
return false;

ac.setBranch(branch);
return true;
}


public boolean requestOverdraft(double amount){

return !currentAccount.requestOverdraft(amount);

}



}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions src/main/java/com/booleanuk/core/Models/domain_model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


| Classes | Methods | Scenario | Outputs |
| ------------- | ------------------------------------------ | ----------------------------------------------------- | ----------------------------------- |
| | | | |
| Account | boolean deposit(double amount) | amount is positive | true |
| | | amount is negative | false |
| Account | boolean withdraw(double amount) | amount is less than current balance | true |
| | | amount is greater than current balance | false |
| Account | createCurrentAccount() | customer already has current account | false |
| | | customer dosen't have current account | true |
| Account | createSavingsAccount() | customer already has savings account | false |
| | | customer dosen't have savings account | true |
| Account | BankStatement getBankStatement(Account ac) | account is created and there exists an bank statement | bankstatement with all transactions |
| | | account dosen't exist | null |
| | | bank statement dosen't exist | null |
| BankStatement | List\<transactions\>getTransactoins() | if there exists transactions | List of all transactions |
| | | no transactions exists | null |
| Account | boolean requestOverdarft(double amount) | amount does not go past limit | true |
| | | amount exceeds limit | false |
| | | | |
| | | | |
| | | | |
| | | | |

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

import static com.booleanuk.core.AccountOperation.DEPOSIT;
import static com.booleanuk.core.AccountOperation.WITHDRAW;

public class SavingsAccount implements Account{


private double balance;
private Enum<Branches> branch;
private final BankStatement bankStatement = new BankStatement();

public SavingsAccount(){
balance = calculateBalance();

}

@Override
public BankStatement getBankstatement() {
return this.bankStatement;
}

@Override
public boolean deposit(double amount) {
if(amount < 0 ) return false;
Transaction t = new Transaction(amount,this.balance+amount,DEPOSIT);
this.bankStatement.add(t);
this.balance+=amount;
return true;
}

@Override
public boolean withdraw(double amount) {
double negative = amount * -1;
if(amount < 0 || this.balance-amount < 0 ) return false;
Transaction t = new Transaction(negative,this.balance + negative, WITHDRAW);
bankStatement.add(t);
this.balance-=amount;

return true;
}

@Override
public double getBalance() {
return this.balance;
}

@Override
public Enum<Branches> getBranch() {
return this.branch;
}

@Override
public void setBranch(Enum<Branches> newBranch) {
this.branch = newBranch;
}

@Override
public boolean requestOverdraft(double amount) {
return false;
}

private double calculateBalance(){

if(bankStatement.getTransactions().isEmpty())
return 0;

double sum = 0;
for (Transaction t : bankStatement.getTransactions())
sum += t.getAmount();

return sum;

}

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

import java.time.LocalDate;

public class Transaction {


private LocalDate date = LocalDate.now();
private double amount;
private double balance;
private Enum<AccountOperation> type;

public Transaction(double amount, double balance, Enum<AccountOperation>type) {
this.amount = amount;
this.balance = balance;
this.type = type;
}

public double getBalance() {
return balance;
}


public double getAmount() {
return amount;
}


public LocalDate getDate() {
return date;
}


public Enum<AccountOperation> getType() {
return type;
}

public void setType(Enum<AccountOperation> type) {
this.type = type;
}
}
Loading
Loading