Skip to content

done #1

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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ target/*

.project
.classpath
.settings
.settings
/target/
59 changes: 59 additions & 0 deletions src/main/java/io/zipcoder/Account.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,63 @@
package io.zipcoder;

import java.util.ArrayList;

public abstract class Account {
public enum transactionType {
DEPOSIT, WITHDRAWAL
}

private AccountHolder accountholder;
private double balance;
private final long ACCOUNTNUMBER;
private ArrayList<Transaction> log;

public Account(AccountHolder accountholder, double balance, long ACCOUNTNUMBER) {
this.accountholder = accountholder;
this.balance = balance;
this.ACCOUNTNUMBER = ACCOUNTNUMBER;
this.log = new ArrayList<Transaction>();
}

public AccountHolder getAccountholder() {
return accountholder;
}

public double getBalance() {
return balance;
}

public long getACCOUNTNUMBER() {
return ACCOUNTNUMBER;
}

public boolean withdrawal(double amount) {
addTransaction(-amount);
return true;
}

public void deposit(double amount) {
// Transaction tr=new Transaction(amount, balance);
// addTransaction(tr);

addTransaction(amount);

}

public String printLog(int n) {
String logPrint = "Transactions:";

for (int i = log.size() - 1; i >= log.size() - n; i--) {
logPrint += "\n" + "amount: " + log.get(i).getAmount() + "\nremaining balance: "
+ log.get(i).getRemBalance();
}
return logPrint;

}

public void addTransaction(double amount) {
log.add(new Transaction(amount, balance));
this.balance = log.get(log.size() - 1).getRemBalance();
}

}
5 changes: 5 additions & 0 deletions src/main/java/io/zipcoder/AccountHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.zipcoder;

public abstract class AccountHolder {

}
12 changes: 12 additions & 0 deletions src/main/java/io/zipcoder/BusinessAccountHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.zipcoder;

public class BusinessAccountHolder extends AccountHolder {
private final String BUSINESSNAME;

public BusinessAccountHolder (String bizname){
this.BUSINESSNAME=bizname;
}
public String getBizName (){
return BUSINESSNAME;
}
}
29 changes: 29 additions & 0 deletions src/main/java/io/zipcoder/CheckingAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.zipcoder;

import io.zipcoder.Account.transactionType;

public class CheckingAccount extends Account {
private boolean noOver;

public CheckingAccount(boolean noOver, AccountHolder accountholder, double balance, long ACCOUNTNUMBER) {
super(accountholder, balance, ACCOUNTNUMBER);
this.noOver = noOver;
}

public boolean isNoOver() {
return noOver;
}

public void setNoOver(boolean noOver) {
this.noOver = noOver;
}

@Override
public void withdrawal(double amount) {
if (!noOver || (noOver && amount<=super.getBalance())){
addTransaction(-amount);
}else
System.out.println("You do not have sufficient funds for this transaction!!!!");
}

}
24 changes: 24 additions & 0 deletions src/main/java/io/zipcoder/InterestAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.zipcoder;

public class InterestAccount extends Account {
private double interestRate;

public InterestAccount(double interestRate, AccountHolder accountholder, double balance, long ACCOUNTNUMBER) {
super(accountholder, balance, ACCOUNTNUMBER);
this.interestRate = interestRate;
}

public double getInterestRate() {
return interestRate;
}

public void setInterestRate(double interestRate) {
this.interestRate = interestRate;
}

public void applyInterest(){
double interestToDeposit = getBalance() * (interestRate/100);
addTransaction(interestToDeposit);
}

}
37 changes: 37 additions & 0 deletions src/main/java/io/zipcoder/PersonalAccountHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.zipcoder;

public class PersonalAccountHolder extends AccountHolder {
private String firstName, lastName, middleInitial;

public PersonalAccountHolder(String firstName, String lastName, String middleInitial) {
this.firstName = firstName;
this.lastName = lastName;
this.middleInitial = middleInitial;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getMiddleInitial() {
return middleInitial;
}

public void setMiddleInitial(String middleInitial) {
this.middleInitial = middleInitial;
}


}
29 changes: 29 additions & 0 deletions src/main/java/io/zipcoder/SavingsAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.zipcoder;

public class SavingsAccount extends InterestAccount {
private boolean noOver;

public SavingsAccount(boolean noOver, double interestRate, AccountHolder accountholder, double balance,
long ACCOUNTNUMBER) {
super(interestRate, accountholder, balance, ACCOUNTNUMBER);
this.noOver = noOver;
}

public boolean isNoOver() {
return noOver;
}

public void setNoOver(boolean noOver) {
this.noOver = noOver;
}
@Override
public boolean withdrawal(double amount) {
if (!noOver || (noOver && amount <= super.getBalance())) {
addTransaction(-amount);
return true;
} else
System.out.println("You do not have sufficient funds for this transaction!!!!");
return false;
}

}
20 changes: 20 additions & 0 deletions src/main/java/io/zipcoder/Transaction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.zipcoder;

public class Transaction {
private final double amount;
private final double remBalance;

public Transaction(double amount, double balance) {
this.amount = amount;
this.remBalance = balance+amount;
}

public double getAmount() {
return amount;
}

public double getRemBalance() {
return remBalance;
}

}
4 changes: 0 additions & 4 deletions src/test/java/io/zipcoder/AccountTest.java

This file was deleted.

20 changes: 20 additions & 0 deletions src/test/java/io/zipcoder/BusinessAccountHolderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.zipcoder;

import org.junit.Assert;
import org.junit.Test;


public class BusinessAccountHolderTest {
@Test
public void BusinessAccountHolderTest() {
//Given
BusinessAccountHolder test = new BusinessAccountHolder("NAME");
String expected="NAME";
//When
String actual = test.getBizName();
//Then
Assert.assertEquals(expected, actual);

}

}
47 changes: 47 additions & 0 deletions src/test/java/io/zipcoder/CheckingAccountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.zipcoder;

import org.junit.Assert;
import org.junit.Test;

public class CheckingAccountTest {

@Test
public void withdrawalTest() {
// Given
PersonalAccountHolder testAccount = new PersonalAccountHolder("halide", "bey", "I");
CheckingAccount testCheckingAccount = new CheckingAccount(true, testAccount, 100.0, 9);
double expected = 50.0;
// When
testCheckingAccount.withdrawal(50);
double actual = testCheckingAccount.getBalance();
// Then
Assert.assertEquals(expected, actual, 0.0);
}

@Test
public void withdrawalNegativeTest() {
// Given
PersonalAccountHolder testAccount = new PersonalAccountHolder("halide", "bey", "I");
CheckingAccount testCheckingAccount = new CheckingAccount(true, testAccount, 100.0, 9);
double expected = 100.0;
// When
testCheckingAccount.withdrawal(150);
double actual = testCheckingAccount.getBalance();
// Then
Assert.assertEquals(expected, actual, 0.0);
}

@Test
public void withdrawalPositiveTest() {
// Given
PersonalAccountHolder testAccount = new PersonalAccountHolder("halide", "bey", "I");
CheckingAccount testCheckingAccount = new CheckingAccount(false, testAccount, 100.0, 9);
double expected = -50.0;
// When
testCheckingAccount.withdrawal(150);
double actual = testCheckingAccount.getBalance();
// Then
Assert.assertEquals(expected, actual, 0.0);
}

}
34 changes: 34 additions & 0 deletions src/test/java/io/zipcoder/InterestAccountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.zipcoder;

import org.junit.Assert;
import org.junit.Test;

public class InterestAccountTest {
@Test
public void applyInterestTest() {
// Given
PersonalAccountHolder testAccount = new PersonalAccountHolder("halide", "bey", "I");
InterestAccount testInterestAccount = new InterestAccount(5.0, testAccount, 100.0, 9);
double expected = 105.0;
// When
testInterestAccount.applyInterest();
double actual = testInterestAccount.getBalance();
// Then
Assert.assertEquals(actual, expected, 0.0);
}

@Test
public void withdrawalTest() {
// Given
PersonalAccountHolder testAccount = new PersonalAccountHolder("halide", "bey", "I");
InterestAccount testCheckingAccount = new InterestAccount(9.0, testAccount, 100.0, 9);

double expected = -50.0;
// When
testCheckingAccount.withdrawal(150);
double actual = testCheckingAccount.getBalance();
// Then
Assert.assertEquals(expected, actual, 0.0);
}

}
18 changes: 18 additions & 0 deletions src/test/java/io/zipcoder/PersonalAccountHolderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.zipcoder;

import org.junit.Assert;
import org.junit.Test;

public class PersonalAccountHolderTest {
@Test
public void PersonalAccountHolderTest(){
//Given
PersonalAccountHolder test= new PersonalAccountHolder("halide", "bey", "I");
String expected="halidebeyI";
//When
String actual = test.getFirstName()+test.getLastName()+test.getMiddleInitial();
//Then
Assert.assertEquals(actual,expected);
}

}
28 changes: 28 additions & 0 deletions src/test/java/io/zipcoder/SavingsAccountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.zipcoder;
import org.junit.Assert;
import org.junit.Test;
public class SavingsAccountTest {
@Test
public void withdrawalTest(){
//Given
PersonalAccountHolder testAccount= new PersonalAccountHolder ("halide","bey","I");
SavingsAccount testSavingsAccount = new SavingsAccount(true, 5.0, testAccount, 100.0, 9);
boolean expected=true;
//When
boolean actual=testSavingsAccount.withdrawal(50);
//Then
Assert.assertEquals(expected, actual);
}
@Test
public void withdrawalNegativeTest(){
//Given
PersonalAccountHolder testAccount= new PersonalAccountHolder ("halide","bey","I");
SavingsAccount testSavingsAccount = new SavingsAccount(true, 5.0, testAccount, 100.0, 9);
boolean expected=false;
//When
boolean actual=testSavingsAccount.withdrawal(150);
//Then
Assert.assertEquals(expected, actual);
}

}
Loading