Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
bff946d
added to isEmailValidTest
mcquill99 Jan 22, 2020
13c72ce
fix isEmailValid method to contain more thorough validation
sradms0 Jan 23, 2020
9d1d1b9
update regex string to accomodate any domain suffix (with min. of 2 c…
sradms0 Jan 23, 2020
7634349
Added tests for Widthdraw and getBalance methods, edited javadoc for …
mcquill99 Jan 26, 2020
18bf9e5
Comments for BankAcctest
Jan 27, 2020
37b0d78
withdraw function
Jan 27, 2020
2c44178
Updated Withdraw method
mcquill99 Jan 28, 2020
91ce52b
Updated Regex function and tests and made withdraw more concise
mcquill99 Jan 28, 2020
7191579
Added tests for IsValidAmount method
mcquill99 Jan 30, 2020
e2a7ce1
Added code for IsAmountValid
mcquill99 Jan 30, 2020
6f8e11c
Added Tests to Withdraw and Constructor
mcquill99 Jan 30, 2020
87768df
Added code to have constructor and withdraw rely on isAmountValid
mcquill99 Jan 30, 2020
dc0da89
Added headers for deposit and transfer methods, and tests
mcquill99 Jan 31, 2020
a563950
Added Implementation for Deposit and Transfer
mcquill99 Jan 31, 2020
7a79657
Added functionality to isAmountValid
mcquill99 Jan 31, 2020
7fdcf9b
Added Bank API Files
mcquill99 Feb 3, 2020
7520f3e
Updated Central Bank File
mcquill99 Feb 3, 2020
8aeda1b
testing branch
ruppatel115 Feb 4, 2020
3423381
Added tests for Savings Account
mcquill99 Feb 4, 2020
b160ebe
Added more tests for Savings Account
mcquill99 Feb 4, 2020
e9ac20e
Added fleshed out Savings Account
mcquill99 Feb 4, 2020
accad2f
Confirm Credentials and Create Account functions and Test
ruppatel115 Feb 4, 2020
3c672f9
Fixed Comments
mcquill99 Feb 5, 2020
90785b2
Started some close account tests
ruppatel115 Feb 5, 2020
1b3e98b
Made Tests
mcquill99 Feb 5, 2020
8853b3b
Made Function to complete tests
mcquill99 Feb 5, 2020
6402d7f
CreateAccount Tests
ruppatel115 Feb 5, 2020
aa51b58
Implementing checkBalance
mbecker5 Feb 5, 2020
4ed7415
Implementing checkBalance
mbecker5 Feb 5, 2020
731bd44
test
ruppatel115 Feb 5, 2020
dfbf89e
updated git ignore
mcquill99 Feb 5, 2020
c89b45b
Merge branch 'master' into checkBalance2
mbecker5 Feb 5, 2020
6adfa28
Merge branch 'master' of https://github.com/mcquill99/SoftwareEnginee…
mbecker5 Feb 5, 2020
84eb279
Updated Git Ignore
mcquill99 Feb 5, 2020
ae8f843
Merge branch 'master' of https://github.com/mcquill99/SoftwareEnginee…
mcquill99 Feb 5, 2020
77b44b9
Merge branch 'master' of https://github.com/mcquill99/SoftwareEnginee…
mcquill99 Feb 5, 2020
bbc87f3
account stuff
ruppatel115 Feb 5, 2020
65cf82a
Fixed merge conflicts in accountConfirmation
ruppatel115 Feb 5, 2020
3ac9024
Fixed merge conflicts for accountConfirmation
ruppatel115 Feb 5, 2020
6be9a17
close account test and function implemented
ruppatel115 Feb 5, 2020
3a07b85
Created Tester classes for each API and added tests to it
ruppatel115 Feb 5, 2020
f439ffb
removed .idea folder from repo and merged master into branch
mcquill99 Feb 5, 2020
fc596f9
Merge branch 'master' into checking-and-savings
mcquill99 Feb 5, 2020
d207726
Removed SoftwareEngineeringPractice.iml and Bank.iml from project, mo…
mcquill99 Feb 5, 2020
1ed38c9
Merge branch 'master' into checking-and-savings
mcquill99 Feb 5, 2020
d65c3a4
file tracking -changed
mcquill99 Feb 5, 2020
dcef5f4
Merge pull request #2 from mcquill99/checking-and-savings
mcquill99 Feb 5, 2020
7a314bd
Updated gitignore
mcquill99 Feb 6, 2020
018b791
Added iml file
mcquill99 Feb 6, 2020
b7451c5
Added tests for withdraw and checkBalance
mcquill99 Feb 6, 2020
a5c8ed6
Added withdraw and getBalance functions to centralBank
mcquill99 Feb 6, 2020
3e3b12b
Merge pull request #3 from mcquill99/withdraw-and-checkBalance
ruppatel115 Feb 6, 2020
596d045
implemented deposit and transfer with testers
ruppatel115 Feb 6, 2020
bf2b9dc
pass all tests for transfer and deposit
ruppatel115 Feb 6, 2020
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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
target/
.idea/
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
.idea/misc.xml
.idea/SoftwareEngineeringPractice.iml

# Generated files
.idea/**/contentModel.xml
Expand Down Expand Up @@ -93,4 +97,6 @@ Icon
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
.apdisk

SoftwareEngineeringPracticeBank.iml
13 changes: 0 additions & 13 deletions .idea/compiler.xml

This file was deleted.

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

This file was deleted.

14 changes: 0 additions & 14 deletions .idea/misc.xml

This file was deleted.

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

This file was deleted.

26 changes: 25 additions & 1 deletion SoftwareEngineeringPractice.iml
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-engine:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-commons:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-runner:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-launcher:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.platform:junit-platform-suite-api:1.0.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.junit.vintage:junit-vintage-engine:4.12.0" level="project" />
</component>
</module>
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);

}
10 changes: 10 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,10 @@
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);



}
119 changes: 119 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,119 @@
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) throws IllegalArgumentException {
if(!accountMap.containsKey(acctId)){
throw new IllegalArgumentException("Account does not exist with name: " + acctId);
}
return accountMap.get(acctId).getBalance();
}

public void withdraw(String acctId, double amount) throws InsufficientFundsException, IllegalArgumentException {
if(!accountMap.containsKey(acctId)){
throw new IllegalArgumentException("Account does not exist with name: " + acctId);
}

accountMap.get(acctId).withdraw(amount);
}


public void deposit(String acctId, double amount) throws IllegalArgumentException {
if(!accountMap.containsKey(acctId)){
throw new IllegalArgumentException("Account does not exist with ID" + acctId);
}

accountMap.get(acctId).deposit(amount);


}

public void transfer(String acctIdToWithdrawFrom, String acctIdToDepositTo, double amount) throws IllegalArgumentException, InsufficientFundsException {
if(!accountMap.containsKey(acctIdToWithdrawFrom) || !accountMap.containsKey(acctIdToDepositTo) || acctIdToWithdrawFrom.equals(acctIdToDepositTo)){
throw new IllegalArgumentException("Account does not exist with IDs given");

}

if(accountMap.get(acctIdToWithdrawFrom).getBalance() < amount){
throw new InsufficientFundsException("Account does not have enough money");
}


accountMap.get(acctIdToWithdrawFrom).withdraw(amount);
accountMap.get(acctIdToDepositTo).deposit(amount);



}

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) {
accountMap.remove(acctId);





}


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

public double calcTotalAssets() {
return 0;
}

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

public void freezeAccount(String acctId) {

}

public void unfreezeAcct(String acctId) {

}

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

public class CheckingAccount extends BankAccount {
/**
* @throws IllegalArgumentException if email is invalid
*/
public CheckingAccount(String email, double startingBalance) {
super(email, startingBalance);
}
}
Loading