Skip to content

Finished the pair coding lab! No UML diagram as of yet #3

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 5 commits 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/
4 changes: 0 additions & 4 deletions src/main/java/io/zipcoder/Account.java

This file was deleted.

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

//import java.util.Date;

public class Transaction {

//private Date timeStamp;
private final String type;
private final double transactionAmount;
private final double newBalance;

public Transaction(String type, double transactionAmount, double newBalance){
this.type = type;
this.transactionAmount = transactionAmount;
this.newBalance = newBalance;
//this.timeStamp = new Date();
}

/**
* @return the transactionAmount
*/
public double getTransactionAmount() {
return transactionAmount;
}
/**
* @return the remaining
*/
public double getRemaining() {
return newBalance;
}

public String toString(){
return String.format("transaction type %s. Transaction amount: �%.2f, new balance is: �%.2f",this.type, getTransactionAmount(), getRemaining());
//return "transaction type " + this.type + ". Transaction amount: �" + this.transactionAmount + ", new balance is: �" + this.newBalance;
}
}
6 changes: 6 additions & 0 deletions src/main/java/io/zipcoder/accountHolders/AccountHolder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.zipcoder.accountHolders;
public abstract class AccountHolder {

public abstract String getName();

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

public class Business extends AccountHolder{

private String businessName;

public Business(String businessName) {
this.businessName = businessName;
}

public String getName(){
return this.getBusinessName();
}

/**
* @return the businessName
*/
public String getBusinessName() {
return businessName;
}

/**
* @param businessName the businessName to set
*/
public void setBusinessName(String businessName) {
this.businessName = businessName;
}

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

public class Person extends AccountHolder{

private String firstName;
private String middleInitials;
private String lastName;


//TODO:
// ??? toString - returns output of getName ???

public Person(String firstName, String middleInitials, String lastName){
setFirstName(firstName);
setMiddleInitials(middleInitials);
setLastName(lastName);
}

public String getName(){
return getFirstName() + " " + getMiddleInitials() + " " + getLastName(); // format??
}

/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @param firstName the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @return the middleInitials
*/
public String getMiddleInitials() {
return middleInitials;
}
/**
* @param middleInitials the middleInitials to set
*/
public void setMiddleInitials(String middleInitials) {
this.middleInitials = middleInitials;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @param lastName the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}

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

import java.util.ArrayList;

import io.zipcoder.Transaction;
import io.zipcoder.accountHolders.AccountHolder;

public abstract class Account {

private final AccountHolder accountHolder;
private double balance;
protected final long accountNumber;
private final ArrayList<Transaction> transactions;

private static long accountNumberIncrementor = 0;

protected Account(AccountHolder accountHolder) {
this.accountHolder = accountHolder;
this.balance = 0.00;
this.transactions = new ArrayList<Transaction>();
this.accountNumber = generateAccountNumber();
}

protected void creditAccount(double amount) {
this.creditAccount("credit account", amount);
}
protected void creditAccount(String transactionType, double amount) {
if (amount >= 0) {
this.balance += amount;
// transaction
this.transactions.add(new Transaction(transactionType, amount, this.balance));
} else {
throw new IllegalArgumentException("amount cannot be negative");
}
}

protected void debitAccount(double amount) {
if (amount >= 0) {
this.balance -= amount;
// transaction
this.transactions.add(new Transaction("debit account", amount, this.balance));
} else {
throw new IllegalArgumentException("amount cannot be negative");
}
}

/**
* @return the accountHolder
*/
public AccountHolder getAccountHolder() {
return accountHolder;
}

/**
* @return the balance
*/
public double getBalance() {
return balance;
}

/**
* @return the accountNumber
*/
public long getAccountNumber() {
return accountNumber;
}

/**
* @return the transactions
*/
public ArrayList<Transaction> getTransactions() {
return (ArrayList<Transaction>) this.transactions.clone();
}

public String getTransactionLog(int n) {

StringBuilder returnBuilder = new StringBuilder("Transaction Log:");
for (int i = transactions.size() -1; i >= transactions.size()-n; i--) {
returnBuilder.append("\n" + transactions.get(i).toString());
}
return returnBuilder.toString();
}

private long generateAccountNumber() {
accountNumberIncrementor++;
return accountNumberIncrementor;
}

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

import io.zipcoder.accountHolders.AccountHolder;

public class CheckingAccount extends Account {

private boolean canHaveOverdraft = false;
private double overdraftLimit = 0.0;

public CheckingAccount(AccountHolder accountHolder,
double overdraftLimit, boolean canHaveOverdraft) {
super(accountHolder);
this.setOverdraftLimit(overdraftLimit);
this.setCanHaveOverdraft(canHaveOverdraft);
}

@Override
public void debitAccount(double amount) {
if (this.canHaveOverdraft() && this.getBalance() - amount >= -(this.getOverdraftLimit())) {
super.debitAccount(amount);
} else if (this.getBalance() - amount >= 0) {
super.debitAccount(amount);
}
}

/**
* @return the canHaveOverdraft
*/
public boolean canHaveOverdraft() {
return canHaveOverdraft;
}

/**
* @param canHaveOverdraft
* the canHaveOverdraft to set
*/
public void setCanHaveOverdraft(boolean canHaveOverdraft) {
this.canHaveOverdraft = canHaveOverdraft;
}

/**
* @return the overdraftLimit
*/
public double getOverdraftLimit() {
return overdraftLimit;
}

/**
* @param overdraftLimit
* the overdraftLimit to set
*/
public void setOverdraftLimit(double overdraftLimit) {
if (overdraftLimit >= 0) {
this.overdraftLimit = overdraftLimit;
} else {
this.overdraftLimit = 0;
}
}

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

public interface InterestEnabledAccount {

/**
* @return the interest
*/
double getInterest();

/**
* @param intrest
* the interest to set, this should be relative to 1 (ie, setting
* interest to 1 is equivalent to 0% interest; 1.01 is equivalent to 1% interest) and cannot be
* negative.
*/
void setInterest(double interest);

/**
* applies interest to the account, automatically debits and logs this as an interest transaction.
*/
void applyInterest();

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

import io.zipcoder.accountHolders.AccountHolder;

public class InvestmentAccount extends Account implements InterestEnabledAccount {

private double interest;

/**
*
* @param accountHolder
* must be an accountHolder
* @param interest
* a value relative to 1 and greater than 0, where 1 is 0%
* interest.
*/
protected InvestmentAccount(AccountHolder accountHolder, double interest) {
super(accountHolder);
this.setInterest(interest);
}

/**
* applies interest to the account, automatically debits and logs this as an
* interest transaction.
*/
public void applyInterest() {
// balance *= this.interest
this.creditAccount("interest", (this.getBalance() * this.interest - this.getBalance()));
}

public double getInterest() {
return this.interest;
}

/**
* @param intrest
* the interest to set, this should be relative to 1 (ie, setting
* interest to 1 is equivalent to 0% interest; 1.01 is equivalent
* to 1% interest) and cannot be negative.
*/
public void setInterest(double interest) {
if (interest >= 0) {
this.interest = interest;
} else {
throw new IllegalArgumentException("interest rate must be relative to 1, and greater than 0.");
}
}

}
Loading