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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
target/
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions SoftwareEngineeringPracticeBank.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4" />
15 changes: 15 additions & 0 deletions src/main/java/edu/ithaca/dragon/bank/AdminAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package edu.ithaca.dragon.bank;

import java.util.Collection;

public interface AdminAPI {

public double calcTotalAssets();

public Collection<String> findAcctIdsWithSuspiciousActivity();

public void freezeAccount(String acctId);

public void unfreezeAcct(String acctId);

}
9 changes: 9 additions & 0 deletions src/main/java/edu/ithaca/dragon/bank/AdvancedAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package edu.ithaca.dragon.bank;

//API to be used by Teller systems
public interface AdvancedAPI extends BasicAPI {

public void createAccount(String acctId, String email, String password, double startingBalance);

public void closeAccount(String acctId);
}
87 changes: 76 additions & 11 deletions src/main/java/edu/ithaca/dragon/bank/BankAccount.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
package edu.ithaca.dragon.bank;

import java.util.regex.Pattern;

public class BankAccount {

private String email;
private double balance;
private String password;
private String acctId;



public BankAccount(String email, double startingBalance) {
this("", email, "", startingBalance);
}

/**
* @throws IllegalArgumentException if email is invalid
*/
public BankAccount(String email, double startingBalance){
public BankAccount(String acctId, String email, String password, double startingBalance){
if (isEmailValid(email)){
this.email = email;
this.balance = startingBalance;
if(isAmountValid(startingBalance)){
this.acctId = acctId;
this.email = email;
this.balance = startingBalance;
this.password = password;
}
else{
throw new IllegalArgumentException("starting Balance of " + startingBalance + "is an invalid amount to add");
}
}
else {
throw new IllegalArgumentException("Email address: " + email + " is invalid, cannot create account");
Expand All @@ -28,19 +45,67 @@ public String getEmail(){

/**
* @post reduces the balance by amount if amount is non-negative and smaller than balance
* throws InsufficientFundsException if the amount is larger than the balance
* If balance is negative or has more than 2 decimal places, throws IllegalArgumentException
*/
public void withdraw (double amount) {
balance -= amount;
public void withdraw (double amount) throws InsufficientFundsException, IllegalArgumentException {
if(!isAmountValid(amount)){
throw new IllegalArgumentException("Amount must have 2 decimal places and must be positive ");
}
if (balance >= amount && amount >= 0) {
balance -= amount;
}
else{
throw new InsufficientFundsException("Amount requested is more than in your account by " + (amount - balance));
}

}


public static boolean isEmailValid(String email){
if (email.indexOf('@') == -1){
return false;
/**
* @post adds to the balance by amount if amount is non-negative and has 2 or less decimal places
* @throws IllegalArgumentException if amount is negative or has more than 2 decimal places
*/
public void deposit(double amount) throws IllegalArgumentException{
if(!isAmountValid(amount)){
throw new IllegalArgumentException("Amount must have 2 or less decimal places and must be positive");
}
else {
return true;
balance += amount;
}

/**
* @post transfers funds from one bank account to the one passed in, as long as amount is non-negative and has 2 or less decimal places
* @throws IllegalArgumentException if amount is negative or has more than 2 decimal places, or if bankAccount to transfer to is the current one
* @throws InsufficientFundsException if amount is larger than current bank account balance
*/
public void transfer(double amount, BankAccount toTransfer) throws InsufficientFundsException, IllegalArgumentException{
if(!isAmountValid(amount) || toTransfer == this){
throw new IllegalArgumentException("Amount must be positive, have 2 decimals or less, and transfer to a new bank account");
}
this.withdraw(amount);
toTransfer.deposit(amount);
}

/**
* @post checks to see if a double is a valid input to be withdrawn
* Returns false if double has more than 2 decimal places, or is negative
*/
public static boolean isAmountValid(double amount){
double positiveRoundOff = Math.abs(Math.round(amount * 100.0) / 100.0);
if(amount != positiveRoundOff){

String doubleCheck = Double.toString(Math.abs(amount));
int integerPlaces = doubleCheck.indexOf('.');
int decimalPlaces = doubleCheck.length() - integerPlaces - 1;
return (decimalPlaces <= 2 || doubleCheck.indexOf('E') != -1) && !(amount < 0);
}
return true;
}

public static boolean isEmailValid(String email){
return email.matches("(\\w)+((_|\\.|-)+\\w+)*@(\\w)+((-)?\\w+)*\\.\\w{2,}$");
}

public String getPassword() {
return password;
}
}
20 changes: 20 additions & 0 deletions src/main/java/edu/ithaca/dragon/bank/BasicAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package edu.ithaca.dragon.bank;

//API to be used by ATMs
public interface BasicAPI {

boolean confirmCredentials(String acctId, String password);

double checkBalance(String acctId);

void withdraw(String acctId, double amount) throws InsufficientFundsException;

void deposit(String acctId, double amount);

void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException;

String transactionHistory(String acctId);



}
95 changes: 95 additions & 0 deletions src/main/java/edu/ithaca/dragon/bank/CentralBank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package edu.ithaca.dragon.bank;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public class CentralBank implements AdvancedAPI, AdminAPI {

//----------------- BasicAPI methods -------------------------//


public Map<String, BankAccount>accountMap = new HashMap<>();




public boolean confirmCredentials(String acctId, String password){
if(accountMap.containsKey(acctId)){
return accountMap.get(acctId).getPassword().equals(password);
}



return false;
}


public double checkBalance(String acctId) {
return 0;
}

public void withdraw(String acctId, double amount) throws InsufficientFundsException {

}

@Override
public double calcTotalAssets() {
return 0;
}

public void deposit(String acctId, double amount) {

}

public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws InsufficientFundsException {

}

public String transactionHistory(String acctId) {
return null;
}


//----------------- AdvancedAPI methods -------------------------//

public void createAccount(String acctId, String email, String password, double startingBalance) {
BankAccount account = new BankAccount(acctId, email, password, startingBalance);
accountMap.put(acctId, account);

}




public void closeAccount(String acctId) {
// CentralBank bank = new CentralBank();
//
// bank.accountMap.remove(acctId);





}


//------------------ AdminAPI methods -------------------------//

public double checkTotalAssets() {
return 0;
}

public Collection<String> findAcctIdsWithSuspiciousActivity() {
return null;
}

public void freezeAccount(String acctId) {

}

public void unfreezeAcct(String acctId) {

}

}
Loading