Skip to content

ATM Lab #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
10 changes: 10 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,15 @@
<artifactId>project-2-atm</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>

</dependencies>


</project>
74 changes: 74 additions & 0 deletions src/main/java/Account.java
Original file line number Diff line number Diff line change
@@ -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));
}


}
6 changes: 6 additions & 0 deletions src/main/java/CheckingsAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class CheckingsAccount extends Account {




}
8 changes: 8 additions & 0 deletions src/main/java/Investment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class Investment extends Account {



}



26 changes: 23 additions & 3 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -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());
}
}


}
6 changes: 6 additions & 0 deletions src/main/java/Menu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class Menu {

scanner keyboard = newScanner(Sysmte.in);
Bank

}
2 changes: 2 additions & 0 deletions src/main/java/SavingsAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class SavingsAccount extends Account{
}
7 changes: 7 additions & 0 deletions src/main/java/Transaction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@



public class Transaction {
}


91 changes: 91 additions & 0 deletions src/main/test/AccountTest.java
Original file line number Diff line number Diff line change
@@ -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);
}




}
7 changes: 7 additions & 0 deletions src/main/test/TransactionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import org.junit.Assert;

import java.math.BigDecimal;

import static org.junit.Assert.*;

public class TransactionTest {