diff --git a/pom.xml b/pom.xml index 9901415..9404b5c 100644 --- a/pom.xml +++ b/pom.xml @@ -8,5 +8,15 @@ project-2-atm 1.0-SNAPSHOT + + + + junit + junit + 4.12 + + + + \ No newline at end of file diff --git a/src/main/java/Account.java b/src/main/java/Account.java new file mode 100644 index 0000000..13fada5 --- /dev/null +++ b/src/main/java/Account.java @@ -0,0 +1,74 @@ +import java.math.BigDecimal; + +public class Account { + + private BigDecimal balance; + private String accountType; + + //set the account name and holder + Account(){ + + } + //constructor to set value for my variable type BigDecimal and variable balance + Account(BigDecimal balance) + { + this.balance = balance; + } + + + //return the value METHOD + public BigDecimal getBalance() + { + return balance; + } + + //gives the value of the balance after it is returned + public void setBalance(BigDecimal balance) + { + this.balance = balance; + } + + + //DEPOSIT METHOD + public void deposit(BigDecimal depositAmount) + { + //get 200 + BigDecimal balance = getBalance(); + + //300 = 200 +100 + balance = balance.add(depositAmount); + + //print 300 + this.setBalance(balance); + } + + // WITHDRAWAL METHOD + public void withdrawal(BigDecimal withdrawalAmount) + { + // get 200 + BigDecimal balance = getBalance(); + + // 150 = 200 - 50 + balance = balance.subtract(withdrawalAmount); + + //print 150 + this.setBalance(balance); + } + + //Transfer METHOD + public void transfer( Account accountTwo, BigDecimal transferAmount) + { + //establish balance = 100 + // transfer amount 50 + //set balance = 50 in account one + + // 50 = 100 - 50 + this.setBalance(getBalance().subtract(transferAmount)); + + //150 = 100 +50 + //print balance in accountTwo + accountTwo.setBalance(accountTwo.getBalance().add(transferAmount)); + } + + +} diff --git a/src/main/java/CheckingsAccount.java b/src/main/java/CheckingsAccount.java new file mode 100644 index 0000000..4ee5c2a --- /dev/null +++ b/src/main/java/CheckingsAccount.java @@ -0,0 +1,6 @@ +public class CheckingsAccount extends Account { + + + + +} diff --git a/src/main/java/Investment.java b/src/main/java/Investment.java new file mode 100644 index 0000000..50c7a41 --- /dev/null +++ b/src/main/java/Investment.java @@ -0,0 +1,8 @@ +public class Investment extends Account { + + + +} + + + diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 05e41a9..6064f92 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,9 +1,29 @@ /** * Created by iyasuwatts on 10/17/17. */ +import java.math.BigDecimal; +import java.text.NumberFormat; +import java.util.Scanner; + public class Main { - public static void main(String[] args){ - + public static void main(String[] args) { + + + + + + // Create and instantiate two Account objects + Account one = new Account(new BigDecimal(50)); + Account two = new Account(new BigDecimal(50)); + //all the things/methods you can do to account one + one.deposit(new BigDecimal(50)); + two.withdrawal(new BigDecimal(20)); + + + System.out.println(one.getBalance()); + System.out.println(two.getBalance()); } -} + + +} \ No newline at end of file diff --git a/src/main/java/Menu.java b/src/main/java/Menu.java new file mode 100644 index 0000000..bc77d16 --- /dev/null +++ b/src/main/java/Menu.java @@ -0,0 +1,6 @@ +public class Menu { + + scanner keyboard = newScanner(Sysmte.in); + Bank + +} diff --git a/src/main/java/SavingsAccount.java b/src/main/java/SavingsAccount.java new file mode 100644 index 0000000..9fcf0c7 --- /dev/null +++ b/src/main/java/SavingsAccount.java @@ -0,0 +1,2 @@ +public class SavingsAccount extends Account{ +} diff --git a/src/main/java/Transaction.java b/src/main/java/Transaction.java new file mode 100644 index 0000000..8107392 --- /dev/null +++ b/src/main/java/Transaction.java @@ -0,0 +1,7 @@ + + + +public class Transaction { +} + + diff --git a/src/main/test/AccountTest.java b/src/main/test/AccountTest.java new file mode 100644 index 0000000..ee5f915 --- /dev/null +++ b/src/main/test/AccountTest.java @@ -0,0 +1,91 @@ +import org.junit.Assert; +import org.junit.Test; +import java.math.BigDecimal; + +public class AccountTest { + + @Test + public void depositTest() { + + //:Given + BigDecimal balance = new BigDecimal(200); + BigDecimal depositAmount = new BigDecimal(100); + Account checkingsAccount = new CheckingsAccount(); + checkingsAccount.setBalance(balance); + BigDecimal expectedBalance = new BigDecimal(300); + + //:When + checkingsAccount.deposit(depositAmount); + BigDecimal actualBalance = checkingsAccount.getBalance(); + + //:Then + Assert.assertEquals("Checking balance", expectedBalance, actualBalance); + + } + + @Test + public void withdrawalTest() { + //Given + BigDecimal balance = new BigDecimal(200); + BigDecimal withdrawalAmount = new BigDecimal(50); + Account checkingsAccount = new CheckingsAccount(); + checkingsAccount.setBalance(balance); + BigDecimal expectedBalance = new BigDecimal(150); + + //When + checkingsAccount.withdrawal(withdrawalAmount); + BigDecimal actualBalance = checkingsAccount.getBalance(); + + //Then + Assert.assertEquals("Checking balance", expectedBalance, actualBalance); + + } + + @Test + public void transferTest() { + + //Given + BigDecimal balance = new BigDecimal(500); + BigDecimal transferAmount = new BigDecimal(20); + Account account1 = new Account(balance); + Account account2 = new Account(balance); + + account1.transfer(account2, transferAmount); + + BigDecimal expectedaccount1Balance = new BigDecimal(480); + BigDecimal expectedaccount2Balance = new BigDecimal(520); + + //When + BigDecimal actualaccount1Balance = account1.getBalance(); + BigDecimal account2Balance = account2.getBalance(); + + //Then + Assert.assertEquals("Account One Balance should equal 480", expectedaccount1Balance, actualaccount1Balance); + Assert.assertEquals("Account Two Balance should equal 520", expectedaccount2Balance, account2Balance); + + + } + + @Test + public void getBalanceTest() { + + //Given + BigDecimal balance = new BigDecimal(400); + Account accountOne = new Account(balance); + + // System.out.println(accountOne.getBalance()); + + BigDecimal expectedBalance = new BigDecimal(400); + + + //When + BigDecimal actualBalance = accountOne.getBalance(); + + //Then + Assert.assertEquals("Balance one", expectedBalance, actualBalance); +} + + + + +} \ No newline at end of file diff --git a/src/main/test/TransactionTest.java b/src/main/test/TransactionTest.java new file mode 100644 index 0000000..f88f645 --- /dev/null +++ b/src/main/test/TransactionTest.java @@ -0,0 +1,7 @@ +import org.junit.Assert; + +import java.math.BigDecimal; + +import static org.junit.Assert.*; + +public class TransactionTest {